i have a very simple question(please answer)

alright this is a very simple question to answer i guess, i just cant figure it out

i m new at C++, i have only been using it for a couple of months in school and am the best in my class and i cant figure this out, i use Visual C++

my question is (now i m asking for a program):

how can i write a program that tells the user ot think of a number between 1 and 100, then the computer guesses the number, and the user tells if his/her number is higher or lower, the computer continues to guess until the number is reached

it looks like a simple question compared to what i have been seeing so if anyone can help me it will be great

thanks
LVL 1
simpsons17371Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

PlanetCppCommented:
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
#include <time.h>

int main(void)
{
     int number,guessed,numguessed,start,end = 100;
     number=guessed=numguessed=start=0;
     char correct;

     srand(time(NULL));

     do
     {
          cout<<"Enter a number from 1-100:";
          cin>>number;
          if(number<1 || number>100)
               cout<<"number out of range.\n";
     }while(!(number>=1) && !(number<=100));
 

     do
     {
          guessed = (rand()%(end-start))+1+start;
          cout<<"I guess "<<guessed;
          cout<<"\nAm i correct (h=higher,l=lower,c=correct):";
          cin>>correct;
          while(correct!='h' && correct!='H' && correct!='l' && correct!='L'
               && correct!='c' && correct!='C')
          {
               cout<<"invalid (h=higher,l=lower,c=correct):";
               cin>>correct;
          }
          ++numguessed;
          switch(correct)
          {
          case 'h':
          case 'H':
                    start = guessed+1;
               break;
          case 'l':
          case 'L':
                    end = guessed-1;
               break;
          case 'c':
          case 'C':
               if(guessed==number)
                    cout<<"i'm sooo psychic! and it only took "<<numguessed<<" guesses.\n";
               else
                    cout<<"ummm ok, actually it didn't.\n";
               break;
          };
     }while(correct!='c' && correct!='C');

    return 0;

}

0
PlanetCppCommented:
sorry my logic was messed up on the initial input, i wrote this in 5 minutes :o\ for more points i spend more time ;o)
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
#include <time.h>

int main(void)
{
     int number,guessed,numguessed,start,end = 100;
     number=guessed=numguessed=start=0;
     char correct;

     srand(time(NULL));

     do
     {
          cout<<"Enter a number from 1-100:";
          cin>>number;
          if(number<1 || number>100)
               cout<<"number out of range.\n";
     }while(number<1 || number>100);
 

     do
     {
          guessed = (rand()%(end-start))+1+start;
          cout<<"I guess "<<guessed;
          cout<<"\nAm i correct (h=higher,l=lower,c=correct):";
          cin>>correct;
          while(correct!='h' && correct!='H' && correct!='l' && correct!='L'
               && correct!='c' && correct!='C')
          {
               cout<<"invalid (h=higher,l=lower,c=correct):";
               cin>>correct;
          }
          ++numguessed;
          switch(correct)
          {
          case 'h':
          case 'H':
                    start = guessed+1;
               break;
          case 'l':
          case 'L':
                    end = guessed-1;
               break;
          case 'c':
          case 'C':
               if(guessed==number)
                    cout<<"i'm sooo psychic! and it only took "<<numguessed<<" guesses.\n";
               else
                    cout<<"ummm ok, actually it didn't.\n";
               break;
          };
     }while(correct!='c' && correct!='C');

    return 0;

}

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
simpsons17371Author Commented:
thanks a lot i will give u all of my 75 points, sry dont have any more i just made this thing...your answer will help me in school and get me some extra credit so thanks again
0
simpsons17371Author Commented:
does anyone actually know how to close a thread or is it just not possible
0
simpsons17371Author Commented:
blah blah blah
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.