Write a program to simulate a 6 star lottery game. The rule is as follows:
1.A lottery ticket cost NT $50.
2.The player can pick six numbers from 1 to 42.
3.There is no duplicate lottery number.
4.The prize is shown as follows:
Reward Item Rule Prize
6 Stars Price 6 matched numbers 500,000
5 Stars Price 5 matched numbers 10,000
4 Stars Price 4 matched numbers 1,000
3 Stars Price 3 matched numbers 200
1. Display a welcome message to the game. A player enters her or his name.
2. A player can select the number of tickets the player wants to buy and decide if the computer selects the numbers or the player selects the numbers.
3. A player enters the numbers or the computer selects the numbers based on the player's decision.
4. Print the receipt.
5.The player can choose to buy more tickets or not.
6. Show the lottery result.
7. Calculate how much the player spends and wins.
8.The player can choose to continue a new game.
編譯結果如下
=================================================
Welcome to the Happy Lottery Game!
Your name: Rita
Rita, welcome to the game!
=================================================
Enter the number of tickets you want to buy: 2
Computer or Self select (C/S)? S
Select numbers: 17 2 6 22 32 42
Select numbers: 10 6 12 7 28 36
-------------------------------------------------
Rita's Receipt:
Total pay: 100
Thanks for your playing Happy Lottery!
=================================================
Play more (Y/N)? Y
=================================================
Enter the number of tickets you want to buy: 1
Computer or Self select (C/P)? P
Select numbers: 33 7 18 26 45 36
-------------------------------------------------
Rita's Receipt:
Total pay: 50
Thanks for your playing Happy Lottery..
=================================================
Play more (Y/N)? N
The lottery result is:
3 7 12 28 38 41
Rita! Congratulations! You won 3 stars.
You spent NT $150 and won NT $200.
=================================================
Quit the game (Y/N)? N
=================================================
Welcome to the lottery game!
Your name: Mary
Rita, welcome to the game!
=================================================
...
...
=================================================
Quit the game (Y/N)? Y
=================================================
Thanks for playing!
我不會寫
投降
welcome (char name[]) {
printf("===========================================\n");
printf("Welcome to the Happy Lottery Game!\nYour name: ");
printf("Your name: ");
scanf("%s", name);
printf("%s, welcome to the game!\n", name);
printf("===========================================\n");
}
main() {
char name[80]; // string = an array of chars
int no_ticket;
int lotto[10][3]; // an array for the selected lottery numbers
char more;
do {
welcome(name);
printf("Enter the number of tickets you want to buy: ");
scanf("%d", &no_ticket);
printf("Select 3 numbers: ");
scanf("%d%d%d", &lotto[0][0], &lotto[0][1], &lotto[0][2]);
printf("You select %d %d %d.\n", lotto[0][0], lotto[0][1], lotto[0][2]);
scanf("%c", &more); // read the newline
printf("=================================================\n");
printf("Play more (Y/N)? ");
scanf("%c", &more);
} while (more == 'Y' || more == 'y');
printf("=================================================\n");
printf("Thanks for playing!\n");
}
只寫到以上的其他就不會寫了