what's wrong with this statement?

Started by
8 comments, last by hothead 19 years, 7 months ago
#include <iostream> using namespace std; int main() { int score; char playAgain; score = 0; char = playAgain; /*<--this one gives me an error. why?*/ cout << "\nscore: " << endl; cout << "playAgain: " << endl; cin.get(); return 0; }
A day without sunshine is like, well...night.
Advertisement
char is a type and you're trying to assign the value of the variable playAgain to it... that can't happen.
Ra
I think you're setting char to equal playAgain when it is undefined.
You cant have a keyword as a variable name and playAgain is currently undefined.
the AP was me
you can do this...

char charName = playAgain;

You need to give the char a name on that line.
oh! then i should go:

playAgain = y, n, whatever
not char = playAgain, right?
A day without sunshine is like, well...night.
Im not sure what you're trying to do here.

If you're trying to assign a value to playAgain, here are some examples...

char playAgain;

playAgain = 'y'; //Assign the char 'y' to playAgain.

Here is another example...

char playAgain = 'y'; //Create a char and assign in the same line.

NOTE: You MUST have the quotes in there.
chars should go into playagain not char( thats just the type definition).
It should be:

char playAgain;
cin >> playAgain;

if(playAgain == 'y' || playAgain == 'Y')
// keep on playing!
else if (playAgain == 'n' || playAgain == 'N')
// quit teh game
else
// that is not a valid choice
try it like this
#include<iostream>using namespace std;int main(){    int score = 0;    char playagain='y';    while(playagain == 'y')        {        cout<<"score:\n"<<score;        cout<<"playagain(y/n)\n";        cin>>playagain;        }                cout<<"bye";        return 0;    }

hope this helps:).
-----------------------------------Panic and anxiety Disorder HQ

This topic is closed to new replies.

Advertisement