Page 1 of 1

C++ problem

Posted: Mon Oct 01, 2007 8:50 pm
by [SD]happynoobing
I'm taking my first C++ class, so im very noobie here. i ran into this problem:

i have a simple program (extremely simple), and it runs (yay :D), but i want to ask the user to input Y/N so that the program will run from the beginning again if the input is Y (basically asks the user if u want it to run again). BUT, i dont know how to do that...

so far i know there's the while loop that can do it, but if i do this:

char c;
while (c == y)
{

blablabla

cout << "Do you want to continue? (Y/N)" << endl;
cin >> c;
}

the program gives me the error of an undeclared y (the one in red).

so obviously this is not the way to do it. any C++ experts out want to lend me a hand?

Posted: Mon Oct 01, 2007 8:51 pm
by TwelveEleven
I *think* it's because you can't use Y as a variable.. Not 100% sure though.. (I only know a little java so..)

Posted: Mon Oct 01, 2007 8:53 pm
by Hellraider
I think the while (c == y) should be while (c == "y")

I'm a noob in programming too lol.

Posted: Mon Oct 01, 2007 9:00 pm
by [SD]happynoobing
Hellraider wrote:I think the while (c == y) should be while (c == "y")

I'm a noob in programming too lol.

then i get this error:
ISO C++ forbids comparison between pointer and integer

Posted: Mon Oct 01, 2007 9:06 pm
by TwelveEleven
I think you must rename y to a bigger variable (more letters) then you have to make your Y/N awnser like 0(=no) and 1(=yes) though I don't know exactly how you need to write it in C++

Posted: Mon Oct 01, 2007 9:33 pm
by [SD]happynoobing
nvm i got it.

it has to be (c == 'y')
single quotes around the y.