# Let diff = the absolute value of (guess - theNumber). If diff is 0, then guess is correct and the program outputs a message indicating that the user guessed the correct number (and this part is unchanged from the original code). But if diff is not 0, then the program outputs the message as follows.
1. If diff is greater than or equal to 50, the program outputs the message indicating that the guess is either "very high" or "very low" depending on if the guess is higher/lower than theNumber.
2. If diff is greater than or equal to 30 (and less than 50), the program outputs the message indicating that the guess is either "high" or "low" depending on if the guess is higher/lower than theNumber.
3. If diff is greater than or equal to 15 (and less than 30), the program outputs the message indicating that the guess is either "moderately high" or "moderately low" depending on if the guess is higher/lower than theNumber.
4. If diff is greater than 0 (and less than 15), the program outputs the message indicating that the guess is either "somewhat high" or "somewhat low" depending on if the guess is higher/lower than theNumber.
# Give the user at most five tries to guess the number.
This is the neutral/ functioning code:
----------------------------------------------------
#include <iostream>
#include <cstdlib> // to use a random number generator
#include <ctime> // to get the current time
using namespace std;
int main()
{
srand(time(0)); // seed randm number generator
int theNumber = rand() % 100 + 1; // random number between 1 and 100
int tries = 0; // variable for the number of tries
int guess; // variable for the user's guess
bool done = false; // a bool variable which indicates the game is/isn't done
// Welcome message first.
cout << "*********** Welcome to Guess My Number **********\n\n";
while (done == false)
{
cout << "Enter a guess (between 1 and 100): ";
cin >> guess;
if (guess == theNumber)
{
cout << " Congratulations!! You guessed the correct number!\n";
done = true;
}
else if (guess < theNumber)
{
cout << "==> Too low. Guess again.\n";
}
else
{
cout << "==> Too high. Guess again.\n";
}
}
// Closing message
cout << endl
<< "****** THANK YOU. COME BACK AGAIN SOON.******\n";
system("pause");
return 0;
}
-----------------------------------------------------------------------
This is where I am stuck, if anyone can point me in the right directions, it would be greatly appreciated!
#include <iostream>
#include <cstdlib> // to use a random number generator
#include <ctime> // to get the current time
using namespace std;
int main()
{
srand(time(0)); // seed randm number generator
int theNumber = rand() % 100 + 1; // random number between 1 and 100
int tries = 0; // variable for the number of tries
int guess; // variable for the user's guess
bool done = false; // a bool variable which indicates the game is/isn't done
// Welcome message first.
cout << "*********** Welcome to Guess My Number **********\n\n";
while (done == false)
{
cout << "Enter a guess (between 1 and 100): ";
cin >> guess;
if (guess == theNumber)
{
cout << " Congratulations!! You guessed the correct number!\n";
done = true;
}
else if (guess <= 50)
{
cout << "==> Very Low. Guess again.\n";
}
else
{
cout << "==> Very High. Guess again.\n";
}
else if (guess <= 30 > 50)
{
cout << "==> Low. Guess again.\n";
}
else
{
cout << "==> High. Guess again.\n";
}
else if (guess <= 15 > 30)
{
cout << "==> Moderately Low. Guess again.\n";
}
else
{
cout << "==> Moderately High. Guess again.\n";
}
else if (guess <= 0 > 15)
{
cout << "==> Somewhat Low. Guess again.\n";
}
else
{
cout << "==> Somewhat High. Guess again.\n";
}
}
// Closing message
cout << endl
<< "****** THANK YOU. COME BACK AGAIN SOON.******\n";
system("pause");
return 0;
}
MOD EDIT: When posting code...USE CODE TAGS!!!
This post has been edited by JackOfAllTrades: 30 September 2010 - 03:54 AM

New Topic/Question
Reply




MultiQuote







|