### Problem with looping

Hello I'm currently creating a guessing game program where the user will be asked to guess the computer generated number. Once the program is finished, at the end the user will be asked if they want to play again. If the user types "Y or Y" the program will loop and when the user types "n or N" it will not loop. Check out my code below.

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576`` ``````#include #include #include #include #include #define g gotoxy void main(){ int a,l,b,guess,row,col,answer,num,clue=5; textcolor(YELLOW); clrscr(); randomize(); a=random(30)+1; b=random(100)+20; num=random(a)+b; clrscr(); for(col=1;col<=79;col++) { g(col,19); cout<<"Í"; g(col,21); cout<<"Í"; } for(row=1;row<=50;row++) { g(1,20); cout<<"º"; g(79,20); cout<<"º"; } for(col=1;col<=77;col++) { g(2,18); cout<<"Wait while the game is loading..."<"; delay(100); } do{ clrscr(); g(15,15); cout<<"Guess the number!"; g(15,17); cout<<"Clue: The number is between:\t"<num)&&(clue<5)) cout<<"\n\nEnter lower!"; g(17,22); cout<<"\nYour estimate is:"; cin>>guess; if(guess!=num) textcolor(CYAN); clue--; if(guess==num) { textcolor(MAGENTA); clue=0; l=1; cout<<"Wow! You're right! The number is\t" << num; } }while(clue!=0); if(l==0) cout<<"\nSorry,you failed to guess the number, the number is\t" << num; cout<<"\n---------------------------------------------------------"; cout<<"\n\tWould you like to play again?[Y/N]"; cin>>answer; if((answer='N')||(answer='n')) clrscr(); textcolor(GREEN); cout<<"\n\n\n\n\t\tYou have chosen to quit. Thanks for playing!"<

after your if statements, you need {} to indicate where they begin and end.

`void main()` should be `int main()`

you don't have `return 0;` at the end of main.

EDIT
`using namespace std;`
Last edited on
I already changed void to int main.

Sir what do you exactly mean with
 after your if statements, you need {} to indicate where they begin and end.

how should I do that? Would you please show me?
You should put

 ``12345678`` ``````int main(){ double x = 0; if ( x < 1 ){ // if ( Expression ) cout << "Hip-hip-hurrei" << endl; // Statement cout << "Hio hoi << endl; } return 0; } ``````

This is valid

 ``123`` ``````if ( x < 1 ) cout << "Hip-hip-hurrei" << endl; // Statement cout << "Hio hoi << endl; ``````

But "Hio hoi" is independent on expression. I think that the first option is what you need.
Topic archived. No new replies allowed.