Jump to content
  • Advertisement
Sign in to follow this  
Gray00

what's wrong with this statement?

This topic is 5041 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!