Tuesday, September 12, 2017

Code Completion Challenge - Guessing Game Solution

Guessing Game Solution
The following program will act as a guessing game in which the user has eight tries to guess a randomly generated number. The program will tell the user each time whether he guessed high or low:
#include <stdlib.h>
#include <iostream>
#include <time.h>
using namespace std;
int main()
{
srand(time(NULL));    
int number=rand()%100; 
int guess=-1;
int trycount=0;
while(guess!=number && trycount<8)

{
cout<<"Please enter a guess: ";
cin>>guess;

if(guess<number)
cout<<"Too low"<<endl;

if(guess>number)
 cout<<"Too high"<<endl;

trycount++;
}
if(guess==number)
cout<<"You guessed the number";
else
cout<<"Sorry, the number was: "<<number;
return 0;
}

5 comments:



  1. If you ever want to change or up your university grades contact cybergolden hacker he'll get it done and show a proof of work done before payment. He's efficient, reliable and affordable. He can also perform all sorts of hacks including text, whatsapp, password decrypt,hack any mobile phone, Escape Bancruptcy, Delete Criminal Records and the rest

    Email: cybergoldenhacker at gmail dot com

    ReplyDelete
  2. thank you for taking the length to discuss this, I vibes strongly that adoration and admittance greater in perform to this difficulty. If practicable, which include earnings know-how, could you thoughts updating your weblog lower back subsidiary opinion? it’s miles enormously useful for me. dark0de market link

    ReplyDelete
  3. I was very impressed by this post, this site has always been pleasant news Thank you very much for such an interesting post, and I meet them more often then I visited this site dark0de market link

    ReplyDelete
  4. Hello I am so delighted I located your blog, I really located you by mistake, while I was watching on google for something else, Anyways I am here now and could just like to say thank for a tremendous post and a all round entertaining website. Please do keep up the great work. dark0de market link

    ReplyDelete
  5. I am happy to find your distinguished way of writing the post. Now you make it easy for me to understand and implement the concept. Thank you for the post.
    hidden wiki link 2021

    ReplyDelete