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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
|
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <ctime>
#include <stdio.h>
#include <string>
#include <sstream>
using namespace std;
void eqOne (short& num, short& x, short& x1, short& x2)
{
num = (rand() + time(0)) % 20;
x1 = (-num - 3) * 2;
x2 = (-x1 - 3) * 2;
x = (-x2 - 3) * 2;
}
void eqTwo (short& num, short& x, short& x1, short& x2)
{
num = (rand() + time(0)) % 20;
x1 = (2 - num) * 2;
x2 = (2 - x1) * 2;
x = (2 - x2) * 2;
}
int main()
{
short y, y1, y2, guess, number;
unsigned short counter[2] = {0};
bool done;
string s;
system("color 1F");
done = false;
eqOne(number, y, y1, y2);
top:
while(!done)
{
while (counter[0] <3)
{
cout << fixed << showpoint;
cout << endl << setw(63) << "Guess the number that logically follows in the pattern" << endl << endl;
cout << setw(31) << number << setw(6) << y1 << setw(6) << y2 << endl << endl;
getline(cin, s);
{
stringstream input( s );
input >> guess;
if (!input)
{
cout << setw(31) << "Sorry but '" << s << "' is not a valid integer." << endl;
input.clear();
input >> guess;
}
}
if (guess == y)
{
counter[1]++;
cout << endl << setw(44) << "That is correct!" << endl;
while (counter[1] == 1)
{
eqTwo(number, y, y1, y2);
goto top;
//I basically use goto to run the program again after I switch to the second equation.
}
while (counter[1] == 2)
{
done = true;
return 1;
}
}
else
if (guess != y)
{
cout << endl << setw(53) << "Wrong answer, please try again." << endl;
counter[0]++;
}
}
while (counter[0] == 3)
{
if (guess != y)
{
system("cls");
cout << setw(43) << "GAME OVER" << endl << endl;
cout << setw(60) << "Better luck next time, thank you for playing." << endl << endl;
return 1;
}
}
}
return 0;
}
|