Silkroad Online Forums

A community forum for the free online game Silkroad Online. Discuss Silkroad Online, read up on guides, and build your character and skills.

Faq Search Members Chat  Register Profile Login

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: C++ problem
PostPosted: Mon Oct 01, 2007 8:50 pm 
Advanced Member
User avatar
Offline

Joined: Jan 2007
Posts: 2349
Location:
Off Topic
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


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 01, 2007 8:51 pm 
Banned User
Offline

Joined: Mar 2007
Posts: 3806
Location: Heaven
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>>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 01, 2007 8:53 pm 
Active Member
User avatar
Offline

Joined: Aug 2006
Posts: 902
Location:
Xian
I think the while (c == y) should be while (c == "y")

I'm a noob in programming too lol.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 01, 2007 9:00 pm 
Advanced Member
User avatar
Offline

Joined: Jan 2007
Posts: 2349
Location:
Off Topic
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


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 01, 2007 9:06 pm 
Banned User
Offline

Joined: Mar 2007
Posts: 3806
Location: Heaven
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>>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 01, 2007 9:33 pm 
Advanced Member
User avatar
Offline

Joined: Jan 2007
Posts: 2349
Location:
Off Topic
nvm i got it.

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

_________________
Image


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 18 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group