Home > Back-end >  New bosses to help
New bosses to help

Time:09-21

The program is running according to
[Error] break statement not within loop or a switch
[Error] the continue statement not within a loop
How to change new o show

# include
# include
# include
# include
# include
H # include "Windows."
Int main ()
{the using namespace STD.
Int a [4], [4] b; Int I, j; Char chong='Y' Int d;
While (chong=='Y' | | chong=='Y')//make sure can be countless times until the game don't choose exit
'Y'System (" CLS ");
Cout<& lt;" Guess the number of games (dropout) input - 1 "& lt; D=0;//game eventually determine whether success and cycle
for(i=0; I<4. I++)
{a [I]=10;
[I]=b;//initialize the AB array
}
Srand ((unsigned) GetTickCount ());
for(i=0; I<4. I++)
[I]=rand () % b;//generated random number from 0 to 9
While (b [0]==b [1])
B [1]=rand () % 10;//that b [0] and [1] different b
While (b [0] [2]==b | | b [1] [2]==b)
B [2]=rand () % 10;//that [0], [2] and b b b [1] different
While (b [3] [0]==b | | b [1] [3]==b | | b [2] [3]==b)
B [3]=rand () % 10;//make sure [3] and [0], b b b b [1], [2] a number of different
Int ca=0, cb.
For (j=10; J> 0; J -)//the game only 10 times
If (ca==4)
{cout<& lt;" Congratulations you won "& lt; Cout<& lt;" Whether the game, (Y/N) "& lt; Chong=getch (); Y/N//input to continue
If (chong=='N' | | chong=='N') exit (1);
If (chong=='Y' | | chong=='Y'); D=1; Break;
}//game victory return 1
if(d!=0) break;
Ca=0; Cb=0;//initialize the prompt "AB"
Cout<& lt;" There are "& lt; for(i=0; I<4. I++)
{cin> A, [I].//initialize input four number
If (a/I==1) exit (1);
}
While (a [0] <0 | | a [0] & gt; 9)
{cout<& lt;" Input the first number is wrong, please input again "& lt; Cin> A, [0].//that input right
}
While (a [1] <0 | | a [1] & gt; 9 | | a [0]==a [1])
{cout<& lt;" Enter the second number is wrong, please input again "& lt; Cin> A, [1].//make sure input correct
}
While (a [2] <0 | | a [2] & gt; 9 | | a [0]==a [2] | | a [1]==a [2])
{cout<& lt;" The third number input is wrong, please input again "& lt; Cin> A, [2].//make sure input correct
}
While (a [3] <0 | | a [3] & gt; 9 | | a [0]==a [3] | | a [2]==a [3])
{cout<& lt;" The fourth number input is wrong, please input again "& lt; Cin> A, [3].//make sure input correct
}
for(i=0; I<4. I++)
If ([I] a [I]==b) ca++;//determine number and position of
If ([1] a [0]==b | | [2] a [0]==b | | [3] a [0]==b) cb++;
If ([0] a [1]==b | | a [1] [2]==b | | [3] a [1]==b) cb++;
If ([0] a [2]==b | | [1] [2]==b | | [3] a [2]==b) cb++;
If ([0] a [3]==b | | [1] a [3]==b | | [2] [3]==b) cb++;
//four the if digital the right position right
for(i=0; I<4. I++)
{
CoutCout<& lt;" ";
Cout<& lt;" A "& lt; }
//the above tips for loop said every time the results
If (d!=0) continue;
Cout<& lt;" It's a pity that you failed "& lt; Cout<& lt;" The answer is: ";

for(i=0; I<4. I++)
{coutCoutCout<& lt;" Whether the game, (Y/N) ";
CoutChong=getch ();
If (chong=='N' | | chong=='N') exit (1);
If (chong=='Y' | | chong=='Y') continue;
}
}

CodePudding user response:

While behind use {} rich, the scope of your expectations are rich
  • Related