5 Replies - 320 Views - Last Post: 13 December 2011 - 03:39 AM Rate Topic: -----

#1 zhenica  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 7
  • Joined: 10-December 11

GUESSING GAME..

Posted 13 December 2011 - 02:47 AM

HOW CAN I MAKE IT THREE TRIALS ONLY???
ITS TRIAL IS UNLIMITTED

#include<iostream>
#include<cstdlib>
#include<ctime>

using namespace std;

int main()
{
srand(time(0));
int number=rand()%1000+1;;
int guess;
cout<<"Im thinking of a number between 1-1000. Take a guess: ";
cin>>guess;

while(guess!=number)
{
if(guess>number)
{
cout<<"Too high,Guess again: ";
cin>>guess;
}
if(guess<number)
{
cout<<"Too low,Guess again: ";
cin>>guess;
}
}
if(guess=number)
{
cout<<"Congrats!! You got it.";
}

return 0;
}


This post has been edited by no2pencil: 13 December 2011 - 02:56 AM
Reason for edit:: Added code tags


Is This A Good Question/Topic? 0
  • +

Replies To: GUESSING GAME..

#2 time4f5  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 57
  • Joined: 02-December 11

Re: GUESSING GAME..

Posted 13 December 2011 - 02:53 AM

you can check out the links at the bottom of the page. that may give some insight.
Was This Post Helpful? 1
  • +
  • -

#3 zhenica  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 7
  • Joined: 10-December 11

Re: GUESSING GAME..

Posted 13 December 2011 - 02:59 AM

sir what should i add in there???
im just a begginer can u help me please
Was This Post Helpful? 0
  • +
  • -

#4 no2pencil  Icon User is online

  • Admiral Fancy Pants
  • member icon

Reputation: 5354
  • View blog
  • Posts: 27,314
  • Joined: 10-May 07

Re: GUESSING GAME..

Posted 13 December 2011 - 03:06 AM

Change this :

while(guess!=number)



to check if number of guesses less than 3.

On either of these :

if(guess>number)
...
if(guess<number)


Increment the number of guesses.
Was This Post Helpful? 2
  • +
  • -

#5 zhenica  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 7
  • Joined: 10-December 11

Re: GUESSING GAME..

Posted 13 December 2011 - 03:17 AM

thnks a lot sir.. U HELPED ME SO MUCH ^_^ IM VERY HAPPY TNKSss.THNKSS..THNKSss..
Now i know how to do this code..
THNKS FOR HELPING SIR.. ^_^
Was This Post Helpful? 1
  • +
  • -

#6 no2pencil  Icon User is online

  • Admiral Fancy Pants
  • member icon

Reputation: 5354
  • View blog
  • Posts: 27,314
  • Joined: 10-May 07

Re: GUESSING GAME..

Posted 13 December 2011 - 03:39 AM

Glad that worked out for you ;)
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1