### Original Game Idea (Simon Says Maths)

Hey, i'm fairly new to programming but I haven't seen this one before,
i'm just posting for some constructive criticism, any ideas for things to add or things that should probably be done differently?

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152`` ``````//Simon Says Maths! #include #include #include #include using namespace std; int simonChecks(int siSays, int userGuess, int sum); void simonSays(int siSays); int sumNumbers(int num1,int num2,int operation); void operatorSelection(int opSelect); int main() { const int MAX_TURNS = 5; int lives = 3, num1, num2, opSelect, currentTurns, siSays, score = 0, extraLife = 0; int sum, userGuess; srand(time(0)); cout << "You are starting with " << lives << " lives.\n"; Sleep(2000); cout << "Follow Simons orders carefully!\n"; Sleep(2000); cout << "Enter '0' if the answer is Against Simons Rule!\n"; Sleep(2000); cout << "When you think you're Ready! Hit Enter to Start! ;)"; cin.ignore(); for(;;) { Sleep(500); system("CLS"); if (lives == 0) break; currentTurns = (rand()%MAX_TURNS)+1; siSays = rand()%2; simonSays(siSays); for(int i = 0;i < currentTurns;i++) { num1 = rand()%10; num2 = rand()%10; opSelect = rand()%3; sum = sumNumbers(num1,num2,opSelect); cout << "What is " << num1; operatorSelection(opSelect); cout << num2 << " = "; cin >> userGuess; userGuess = simonChecks(siSays, userGuess, sum); if (userGuess == sum){ cout << "Correct!\n"; extraLife++; score++; Sleep(500); if (extraLife == 15) { lives++; cout << "You gained an Extra Life!\n"; Sleep(1500); cout << "You now have " << lives << " lives!\n"; Sleep(2500); extraLife = 0; } } else { lives--; cout << "You have " << lives << " lives remaining!\n"; Sleep(500); if (lives == 0) break; } } } cout << "GAME OVER! You Have No Lives Left!\n"; Sleep(2000); cout << "Your final score is: " << score; Sleep(3000); } int sumNumbers(int a, int b, int op) { int sum; switch (op) { case 0: sum = a*b; break; case 1: sum = a+b; break; case 2: sum = a-b; break; default: cout << "Error: Sum calculator broken!"; } return sum; } void operatorSelection(int opSelect) { switch (opSelect) { case 0: cout << " * "; break; case 1: cout << " + "; break; case 2: cout << " - "; break; default: cout << "Error: Broken Operator!"; } } int simonChecks(int siSays, int userGuess, int sum) { if (siSays == 1) { // Odds if (sum%2 != 0) { //if it is an Odd answer return userGuess; } else if (sum%2 == 0 && userGuess == 0) { return sum; } else if (sum%2 == 0 && userGuess != 0) { cout << "You went against Simons Rule!\n"; if (sum != -1) { return -1; } else { return -2; } } else if (sum != -1) { return -1; } else { return -2; } } if (siSays == 0) { // Evens if (userGuess%2 == 0) { return userGuess; } else if (sum%2 != 0 && userGuess == 0){ return sum; } else if (sum%2 != 0 && userGuess != 0){ cout << "You went against Simons Rule!\n"; if (sum != -1) { return -1; } else { return -2; } } else if (sum != -1){ return -1; } else { return -2; } } } void simonSays(int siSays) { if (siSays == 1) { cout << "SIMON SAYS: ANSWER ODDS ONLY!\n"; } else if (siSays == 0) { cout << "SIMON SAYS: ANSWER EVENS ONLY!\n"; } else { cout << "Error: Odd/Even Selection!\n"; } }``````

please go easy on me, Lostsoulparty.
It is a bad style of programming to use such numerous declarations. Usually Straustrup demonstrates such a bad style in his books on programming.:)

 ``12`` `````` int lives = 3, num1, num2, opSelect, currentTurns, siSays, score = 0, extraLife = 0; int sum, userGuess;``````

These declarations say nothing to the user that reads the code. Are all declared variables used in the same algorithmic task of the program or they are used in different algorithmic tasks of the program? Why is score initialized by 0? What is the magic number 3?
You should declare variables before their immediate usage.
Last edited on
Thanks for the advice and I hadn't even noticed that i'd put 2 different lines of int declarations haha. I will improve the code! :)
Topic archived. No new replies allowed.