help with user confirmation in a while loop

hey guys, this is my first time on this forum and i am in need of some help with a small detail of my assignment. here is what i have so far.

#include <iostream>
#include <ctime>
using namespace std;
int main()
{


while (Y == answer)
{
srand (time(0));
int Age = rand()%140 ;

cout<< " You are " <<Age <<endl;

cout<< " would you like me to try again? type Y for yes, type N for no. ";
int answer;
cin>> answer;
}

system("pause");
return 0;
}
the auto correct states y as undeclared but im not sure how to declare Y or fix this program. any help would be appreciated, thank you.
It is saying that because you did not single quote the Y. So it should be more like

1
2
3
4
while('Y' == answer)
{
//
}


You also might want to consider using do while loop instead of a while since you declared the variable answer is inside the loop.
Last edited on
i took your advice and changed it to a do while loop but now my problem is i cannot get it to restart and guess again. any advice
#include <iostream>

#include <ctime>
using namespace std;
int main()
{
cout<< "would you like me to guess your age, type Y for yes, N for no.";
int answer;
cin>> answer;

do
{
srand (time(0));
int Age = rand()%140 ;

cout<< " You are " <<Age <<endl;

cout<< " would you like me to try again? type Y for yes, type Y for no. ";
int answer;
cin>> answer;
}while (answer=='Y');
system("pause");
return 0;

}
Topic archived. No new replies allowed.