I'm new user of the tek-tips and I need some
desperate help!!
On a program that chooses the number to be guessed by
selecting an integer at random in the range of 1 to
1000. The program then types:
I have a number between 1 and 1000
Can you guess my number?
Please type your first guess.
The player then types a first guess. The program
responds with one of the following:
1. Excellent! You guessed the number!
Would you like to play again (y or n)?
2. Too low. Try again
3. Too high. Try again
It was done in C but I couldn' understand it. (I'm new
to C++, and have never done C) My program is written
below and always gives me an infinite Could anyone help me?
Thanx!!!
#include <iostream>
#include <cstdlib>
using std::cout;
using std::cin;
using std::endl;
double guessed_num;
char response;
double rand_num;
double i;
int main()
{
rand_num = 1+ rand() % 1000;
do
{
cout << "I have a number between 1 & 1000.";
cout << "\nCan you guess my number?";
cout << "\n\nPlease type your first guess: ";
cin >> guessed_num;
if(guessed_num < 1 || guessed_num > 1000)
{
cout << "\nPlease enter a number between 1 & 1000";
cin >> guessed_num;
}
while (guessed_num != rand_num)
{
if(guessed_num < rand_num)
cout << "\nToo low. Try again.";
else if(guessed_num > rand_num)
cout << "\nToo high. Try again.";
}
cout<< "Excellent You've guessed the correct number";
cout<< "would you like to play again (y or n)?";
cin >> response;
} while(response != 'n')
return 0;
}
desperate help!!
On a program that chooses the number to be guessed by
selecting an integer at random in the range of 1 to
1000. The program then types:
I have a number between 1 and 1000
Can you guess my number?
Please type your first guess.
The player then types a first guess. The program
responds with one of the following:
1. Excellent! You guessed the number!
Would you like to play again (y or n)?
2. Too low. Try again
3. Too high. Try again
It was done in C but I couldn' understand it. (I'm new
to C++, and have never done C) My program is written
below and always gives me an infinite Could anyone help me?
Thanx!!!
#include <iostream>
#include <cstdlib>
using std::cout;
using std::cin;
using std::endl;
double guessed_num;
char response;
double rand_num;
double i;
int main()
{
rand_num = 1+ rand() % 1000;
do
{
cout << "I have a number between 1 & 1000.";
cout << "\nCan you guess my number?";
cout << "\n\nPlease type your first guess: ";
cin >> guessed_num;
if(guessed_num < 1 || guessed_num > 1000)
{
cout << "\nPlease enter a number between 1 & 1000";
cin >> guessed_num;
}
while (guessed_num != rand_num)
{
if(guessed_num < rand_num)
cout << "\nToo low. Try again.";
else if(guessed_num > rand_num)
cout << "\nToo high. Try again.";
}
cout<< "Excellent You've guessed the correct number";
cout<< "would you like to play again (y or n)?";
cin >> response;
} while(response != 'n')
return 0;
}