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.
Code:
#include<iostream.h>#include<stdio.h>
#include<dos.h>
#include<stdlib.h>
#include<conio.h>
#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..."<<endl;
g(col+1,20);
cout<<">";
delay(100);
}
do{
clrscr();
g(15,15);
cout<<"Guess the number!";
g(15,17);
cout<<"Clue: The number is between:\t"<<a <<"\tand\t" <<b+a;
g(15,19);
cout<<"Remaining number of trials:\t"<<clue;
textcolor(GREEN);
if((guess<num))
cout<<"\n\nEnter higher!";
if((guess>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!"<<endl;
getch();
}
I can't loop this program please help me with it. Thanks in advance!