Thread: program is freaking out on me

  1. #1
    Registered User
    Join Date
    Oct 2005

    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.

    // Simple Math Game
    #include <iostream>
    #include <ctime>
    #include <cstdlib>
    using namespace std;
    int main()
        //seed out random numbers
        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;
                        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";
    ps: didn't add the final part to check if points == 10 yet

  2. #2
    Registered User
    Join Date
    Aug 2005
    just declare again as char and it should work as expeced.

  3. #3
    Registered User
    Join Date
    Oct 2005
    duh, i should have known that...and i should have looked more closely at it b4 posting...thanx though

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 01:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 01:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM