#include <iostream>
#include <cstdio>
#include <cstdlib>
usingnamespace std;
int main ()
{
int which;
int num;
int guess;
int lives = 5;
which = rand() % 17;
switch (which)
{
case 1:
num = 0000;
break;
case 2:
num = 0001;
break;
case 3:
num = 0011;
break;
case 4:
num = 0111;
break;
case 5:
num = 1111;
break;
case 6:
num = 1110;
break;
case 7:
num = 1100;
break;
case 8:
num = 1000;
break;
case 9:
num = 1001;
break;
case 10:
num = 1011;
break;
case 11:
num = 1101;
break;
case 12:
num = 0110;
break;
case 13:
num = 0100;
break;
case 14:
num = 0010;
break;
case 15:
num = 0101;
break;
case 16:
num = 1010;
break;
}
cout << "Please guess a nibble: ";
cin >> guess;
if (guess == num)
{
int yn;
cout << "Correct! Would you like to play again? (1/2): ";
cin >> yn;
switch (yn)
{
case 1:
main();
break;
case 2:
return 0;
}
}
else {
if (lives == 0)
{
int again;
cout << "Your lives are up. Would you like to play again? (1/2): ";
switch (again)
{
case 1:
main();
break;
case 2:
return 0;
}
cout << "Sorry, that is not right. Try again.";
lives = lives - 1;
main();
}
return 0;
}
system("PAUSE");
}
if (lives == 0)
{
int again;
cout << "Your lives are up. Would you like to play again? (1/2): ";
switch (again)
{
case 1:
main();
break;
case 2:
return 0;
}
cout << "Sorry, that is not right. Try again.";
lives = lives - 1;
main();
}
// what if lives is not 0 ? you break the program here
return 0;