i am running the case statement to randomly pick either heads or tails but says its neither.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
#include <iostream>
#include <string>
using namespace std;
int main()
{
string coin_quess;
string coin;
int score;
score = 1;
while (true)
{
cout << "coin toss simulator" << endl;
cout << "Heads or tails: ";
cin >> coin_quess;
int question = rand() % 1;
switch (question)
{
case 1:
coin = "heads";
//test //cout << coin << endl;
case 2:
coin = "tails";
//test //cout << coin << endl;
}
if (coin_quess == coin)
{
cout << "CORRECT" << endl;
score++;
cout << score << endl;
}
else
{
cout << "INCORRECT" << endl;
cout << score << endl;
}
}
return 0;
}
|
Last edited on
You'd want to mod by 2; causing it to modulate every time the value is 2 or more - forcing a value of less than 2 to be available.
Other than that, your above code should not compile because you're missing headers.
Also, you may to include a break; at line 24 before the next case, else it'll fall through to the second case.
Hope this helps.
Edit: Also, case should be 0 and 1; unless your expecting 1 and 2.
If 1 and 2, simply add 1 to the total rand after modding by 2.
Last edited on
What headers am i missing because it compiles