Write a simulation of the dice gambling game, suppose you have 10 yuan, is responsible for the dice casino, every roll, you guess the dice up side points, such as right, your money plus 1 yuan, otherwise your money to buckle a yuan, circulation, this process until you lost money, or to play 100 times, when you lose the light output after playing the number of times or 100 times the amount of money you have,
CodePudding user response:
refer to the original poster weixin_57594870 response: write a simulation of the dice gambling game, suppose you have 10 yuan, is responsible for the dice casino, every roll, you guess the dice up side points, such as right, your money plus 1 yuan, otherwise your money to buckle a yuan, circulation, this process until you lost money, or to play 100 times, when you lose the light output after playing the number of times or 100 times the amount of money you have, Your program logic is very chaotic, you can read their application in the dry? Suggest you to draw a flow chart, and then according to the flow chart of programming, CodePudding user response:
The Random Random=new Random (); Int count=100; Int money=10; While (the count & gt; 0 & amp; & Money & gt; 0 { Int guessNum=random. NextInt (6) + 1; Int realityNum=random. NextInt (6) + 1; If (guessNum==realityNum) { Money++; } else { Money -; } The count -; } System. Out.println (String format (" play the number of times: % s. Remaining amount: % s ", the count, money)); CodePudding user response:
Public static void main (String [] args) { Scanner input=new Scanner(System.in);//keyboard receive value System. The out. Println (" please enter the money: "); Int money=input. NextInt (); Int jushu=0;//game While (true) { Int XTSJS=(int) (Math. The random () * 6) + 1;//system random number System. The out. Println (" please input your guess points: "); Int CAI=input. NextInt ();//enter his guess points System. The out. Println (" System roll the dice "+ XTSJS); If (XTSJS==CAI) { Money++; Jushu++; System. The out. Println (" guessed it win $1 "); } else { Money -; Jushu++; System. The out. Println (" guess wrong lose one yuan "); } If (money==0) { System. Out.println (" you have lost all, game over!" ); System. The out. Println (" you played "+ jushu +" bureau "); break; {} else if (jushu==100) System. The out. Println (" game has to "+ jushu +" bureau "); System. The out. Println (" you now have "+ money +" RMB "); break; } } } CodePudding user response:
Logic is very chaotic CodePudding user response:
reference 5 floor weixin_57594870 reply: logic really chaotic Beginners will draw a flow chart is clear