The task is to modify a program that guesses numbers by doing:
if diff is %26gt;= 50, program outputs message saying number guessed is too high (if guess is %26gt; number) and too low(if guess is %26lt; number).
it goes on through if diff is %26gt;= 30 and %26lt;50; if diff %26gt;=15 and %26lt;30; if diff is %26gt;= 0 and %26lt;15.
Here is what i have so far:
#include %26lt;iostream%26gt;
#include %26lt;ctime%26gt;
using namespace std;
int main()
{
int number,num_guess[5],diff, counter, picked_num, time;
bool finished;
diff = abs(number - num_guess[5]);
finished = false;
{
cout%26lt;%26lt;"Enter a number that is %26lt; or = 0, and %26gt;100."%26lt;%26lt;endl;
cin%26gt;%26gt;num_guess[5];
counter = 5;}
if (diff == 0)
{
cout%26lt;%26lt;"Correct!!!!"%26lt;%26lt;endl;
finished = true;
}
while(diff %26gt;= 50)
{
if (num_guess[5] %26gt; number)
{
cout%26lt;%26lt;"VERY HIGH!!"%26lt;%26lt;endl;
cout%26lt;%26lt;"Guess Again."%26lt;%26lt;endl;
}
else if (num_guess[5] %26lt; number)
{
cout%26lt;%26lt;"VERY LOW!!"%26lt;%26lt;endl;
cout%26lt;%26lt;"Guess Again."%26lt;%26lt;endl;
}
else
{
cout%26lt;%26lt;""%26lt;%26lt;endl;
}
}
while((diff %26gt;= 30)%26amp;%26amp;(diff %26lt; 50))
{
if (num_guess[5] %26gt; number)
{
cout%26lt;%26lt;"HIGH!!"%26lt;%26lt;endl;
cout%26lt;%26lt;"Guess Again."%26lt;%26lt;endl;
}
else if (num_guess[5] %26lt; number)
{
cout%26lt;%26lt;"LOW!!"%26lt;%26lt;endl;
cout%26lt;%26lt;"Guess Again."%26lt;%26lt;endl;
}
else
{
cout%26lt;%26lt;""%26lt;%26lt;endl;
}
}
while ((diff %26gt;= 15)%26amp;%26amp;(diff %26lt; 30))
{
if (num_guess[5] %26gt; number)
{
cout%26lt;%26lt;"Moderatley High!"%26lt;%26lt;endl;
cout%26lt;%26lt;"Guess Again."%26lt;%26lt;endl;
}
else if (num_guess[5] %26lt; number)
{
cout%26lt;%26lt;" Moderatley Low"%26lt;%26lt;endl;
cout%26lt;%26lt;"Guess Again."%26lt;%26lt;endl;
}
else
{
cout%26lt;%26lt;""%26lt;%26lt;endl;
}
}
while ((diff %26gt;= 0)%26amp;%26amp;(diff %26lt; 15))
{
if (num_guess[5] %26gt; number)
{
cout%26lt;%26lt;"Somewhat High."%26lt;%26lt;endl;
cout%26lt;%26lt;"Guess Again."%26lt;%26lt;endl;
}
else if (num_guess[5] %26lt; number)
{
cout%26lt;%26lt;"Somewhat Low."%26lt;%26lt;endl;
cout%26lt;%26lt;"Guess Again."%26lt;%26lt;endl;
}
else
{
cout%26lt;%26lt;""%26lt;%26lt;endl;
}
}
system("PAUSE");
return 0;
}
What is wrong with My Program? I am using C++. It compiles, but doesn't run right.?
1) num_guess shouldn't be an array. (Get rid of the [5] following it.
2) Don't calculate diff until AFTER getting the value of num_guess.
3) you're whole structure needs to be revisited. Here's some pseudo code...
1) initialize variables and select a random number
2) Get input from users
3) while input doesn't match random number...
a) calculate diff
b) if guess %26gt; random number, print "too high"
c) otherwise print "too low"
d) print "guess again"
Reply:Long question
no answer
looks good to me
blazing star
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment