what's wrong with this statement?
#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;
}
char is a type and you're trying to assign the value of the variable playAgain to it... that can't happen.
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.
You cant have a keyword as a variable name and playAgain is currently undefined.
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.
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.
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
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
hope this helps:).
#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:).
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement