For the program to repeat itself, you should put the whole thing inside of a while loop which runs until a variable (I prefer using the word "end" as the variable name) changes to 1, like so:
Code:
int main ()
{
int end;
int everything_else;
while ( end == 0 )
{
blah blah blah
if ( a == "R" || a == "P" || a == "S" )
end = 1;
}
return 0;
}
This will have the program continually loop until the input is either R, P, or S. Oh, and its better to have the input looked for be lower case, just because nobody's going to want to hold shift and most will try the program without putting it in caps.
For the random number, your going to need something like srand() (http://www.cplusplus.com/reference/c...cstdlib/srand/), though thats not completely random (they refer to it as pseudo-random the whole time), and actually tends towards the lower part of the numbers your trying to get as output and has predictable output.
For the program to repeat itself, you should put the whole thing inside of a while loop which runs until a variable (I prefer using the word "end" as the variable name) changes to 1, like so:
Code:
int main ()
{
int end;
int everything_else;
while ( end == 0 )
{
blah blah blah
if ( a == "R" || a == "P" || a == "S" )
end = 1;
}
return 0;
}
This will have the program continually loop until the input is either R, P, or S. Oh, and its better to have the input looked for be lower case, just because nobody's going to want to hold shift and most will try the program without putting it in caps.
You're right, but stylistically, I'd use a bool. Don't forget to initialize it, and watch the and/or logic there.
Code:
int main ()
{
bool end = false;
int everything_else;
while (!end )
{
blah blah blah
if ( a != "R" && a != "P" && a != "S" )
end = true;
}
return 0;
}
You're right, but stylistically, I'd use a bool. Don't forget to initialize it, and watch the and/or logic there. ...
I nomally don't use a variable in the while condition but use an infinite loop and break the loop when the error condition occurs:
Code:
int main()
{
while (true)
{
...
if (input == 'q') // break the loop when the user types q for quit.
break;
}
return 0;
}
Though the above seems to be more dangerous it actually is less error-prone cause the break would work immediately while the check on 'end' variable works at begin of next loop cycle.
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.