Author |
Message |
jonos
|
Posted: Thu Feb 12, 2004 10:40 pm Post subject: re - initializing a variable |
|
|
i don't think that is the word for this but i want to set a variable to add one to itself after an if statment. i have tried:
points = points+1
points++
points+1
points = points++
and they don't work.
this is what im trying to do:
code: |
cout << "is the donkey going north?" << endl;
cin >> ans;
if (ans =="y")
{
points++;
}
|
if anyone knows the problem, could you ;lease help me thanks |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Catalyst
|
Posted: Thu Feb 12, 2004 11:11 pm Post subject: (No subject) |
|
|
code: |
points++;
points = points+1 ;
points+=1;
|
all should work
maybe some more the code would help |
|
|
|
|
|
jonos
|
Posted: Fri Feb 13, 2004 11:57 am Post subject: (No subject) |
|
|
lame communist exposer:
code: |
cout << "Have you ever felt pride in hearing the exclamation of Mother Russia?" << endl;
cin >> ans;
if (ans == "y")
{
points ++;
}
cout << points << endl;
cout << "Have you ever read the Communist Manifesto, and thought it very enlightening?" << endl;
cin >> ans;
if (ans == "y")
{
points++;
}
cout << "Have you ever visited sovietempire.com?" << endl;
cin >> ans;
if (ans =="y")
{
points+1;
}
cout << "Communist Answers Communicated: ";
cout << points; |
it compiles and everything, but it when it says
Communist Answers Communicated, it says 0 instead of what should be there, such as 1, 2, or 3 depending on the answer given. |
|
|
|
|
|
wtd
|
Posted: Fri Feb 13, 2004 1:19 pm Post subject: (No subject) |
|
|
You want to have declared
at the beginning of this function. |
|
|
|
|
|
Andy
|
Posted: Sat Feb 14, 2004 5:39 pm Post subject: (No subject) |
|
|
int points=0; u mean |
|
|
|
|
|
wtd
|
Posted: Sat Feb 14, 2004 6:21 pm Post subject: (No subject) |
|
|
dodge_tomahawk wrote: int points=0; u mean
Typo. So sue me! |
|
|
|
|
|
McKenzie
|
Posted: Sat Feb 14, 2004 6:25 pm Post subject: (No subject) |
|
|
My guess is that the problem is probably with
Quote: ans == "y"
how was ans declared:
1. char ans;
use ans =='y'
2. char ans[2];
use strcmp(ans,"y")==0
3. string ans;
ans == "y" // i.e. my guess was wrong |
|
|
|
|
|
jonos
|
Posted: Sat Feb 14, 2004 11:41 pm Post subject: (No subject) |
|
|
wow, thanks mckenzie, that was the problem, i had the variable as:
char points[1];
for some reason, i forgot to take out the one cause that is useless i think for my purpose cause char is already 1.
it works now |
|
|
|
|
|
Sponsor Sponsor
|
|
|
|