# program is freaking out on me

• 12-04-2005
Rubiks14
program is freaking out on me
alright i made just a simple little math game using a lot of the i've learned from the first 3 chapters of "Beginning C++ Game Programming" and it works fine the first time through the loop but when i tell it that i want to play again it just keeps going through the loop and doesnt stop. dunno what is wrong with it...i've tried adding cin.ignore(); after all my inputs but it didn't work so wondering if u guys can figure it out.

Code:

```// Simple Math Game #include <iostream> #include <ctime> #include <cstdlib> using namespace std; int main() {     //seed out random numbers     srand(time(0));         int points = 0;     int guess;     int again = 'y';         cout << "\t\t**********Welcome To The Math Quiz Game**********";     cout << "\n\nHow to play: A random problem will be generated and the player has";     cout << "\nto guess the correct answer to earn points. The player will get one";     cout << "\npoint for each answer he/she gets right and will lose one point for";     cout << "\neach answer he/she gets wrong. If the player scores 10 points he/she";     cout << "\nwins the game.";         while (again != 'n')     {           int num1 = (rand() % 100) + 1;           int num2 = (rand() % 100) + 1;                     cout << "\n\nThe problem is: " << num1 << " + " << num2 << " ";           int answer = num1 + num2;                     cin >> guess;                     if (guess == answer)           {                     cout << "Correct! you get 1 point";                     points += 1;           }           else           {                     cout << "Wrong! you lose 1 point";                     points -= 1;           }                     cout << "\n\nyou have " << points << " points";                     cout << "\n\nwould you like to play again (y/n) ";           cin >> again;     }         cout << "Bye";         cin.ignore();     cin.get(); }```
ps: didn't add the final part to check if points == 10 yet
• 12-04-2005
ZuK
just declare again as char and it should work as expeced.
Kurt
• 12-04-2005
Rubiks14
duh, i should have known that...and i should have looked more closely at it b4 posting...thanx though :p