Unhandled exception

I have written this program, which compiles with no warnings and no errors, but when I run it, it seems to either freeze with the error "Unhandled exception at 0x01181c67 in wk2.exe: 0xC0000094: Integer division by zero." and I have to click on break from the box that pops up or the program just continues looping infinitely. Any ideas as to what is wrong?



#include <iostream>
#include <time.h>
#include <stdlib.h>

using namespace std;



int main()
{

int play_again;


do
{

int max;
cout << "How many random numbers?";
cin >> max;


srand( (unsigned) time(0) );

int value;
value = rand() % max + 1 ;
max -= 1;




cout << "Enter your guess: ";
int guess; cin >> guess;



while (guess != value)
{
if (guess <= value)
{cout << "Too low" << endl;
cout << "try again: ";
cin >> guess;}

else if (guess >= value)
{cout << "Too high" << endl;
cout << "try again: ";
cin >> guess;}
}



cout << "YOU WIN!" << endl;
cout << "Would you like to play again?" << endl;
cin >> play_again;



}while (play_again != 'n');


cout << "ok" << endl;


return (0);
}

int play_again; while (play_again != 'n');

Why do you store a character in an int?
Store it in a char play_again instead and it won't throw errors.
I'm just wondering, to anyone who may know, why this program takes ages to link after compilation? It also takes a few seconds to do anything when running it. I've noticed a few programs doing this (maybe when using cin >>). I'm using VS 2008.
Thanks bluezor. That seemed to work.
Can't think why that would make any difference.
Topic archived. No new replies allowed.