C++ problem

Anything else. Post a funny site or tell us about yourself. Discuss current events or whatever else you want. Post off topic threads here.
Post Reply
User avatar
[SD]happynoobing
Advanced Member
Posts: 2349
Joined: Thu Jan 04, 2007 2:06 am
Quick Reply: Yes
Location: Off Topic

C++ problem

Post 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?
Image

TwelveEleven
Veteran Member
Posts: 3806
Joined: Sat Mar 17, 2007 1:11 am
Quick Reply: Yes
Location: Heaven
Contact:

Post 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..)
<<banned from SRF for proof of botting. -SG>>

User avatar
Hellraider
Active Member
Posts: 902
Joined: Sat Aug 12, 2006 4:43 pm
Quick Reply: Yes
Location: Xian

Post by Hellraider »

I think the while (c == y) should be while (c == "y")

I'm a noob in programming too lol.

User avatar
[SD]happynoobing
Advanced Member
Posts: 2349
Joined: Thu Jan 04, 2007 2:06 am
Quick Reply: Yes
Location: Off Topic

Post 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
Image

TwelveEleven
Veteran Member
Posts: 3806
Joined: Sat Mar 17, 2007 1:11 am
Quick Reply: Yes
Location: Heaven
Contact:

Post 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++
<<banned from SRF for proof of botting. -SG>>

User avatar
[SD]happynoobing
Advanced Member
Posts: 2349
Joined: Thu Jan 04, 2007 2:06 am
Quick Reply: Yes
Location: Off Topic

Post by [SD]happynoobing »

nvm i got it.

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

Post Reply

Return to “Off Topic Lounge”