Sign in to follow this  
Gray00

what's wrong with this statement?

Recommended Posts

#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; }

Share this post


Link to post
Share on other sites
char is a type and you're trying to assign the value of the variable playAgain to it... that can't happen.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
chars should go into playagain not char( thats just the type definition).

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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:).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this