Guess the number - chanscor=100/totchan/score for each successful chance do cout<< Sheet1 Page 2 cout<<" Your score

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Sheet1 Page 1 /* HIGH/LOW GAME */ #include<iostream.h> #include<conio.h> #include<stdlib.h> /* This program plays a simple game.The computer picks a random number from 0 to 100, and the user tries to guess the number. */ const int totchan=7 void main() { int number int guess int chances=0,score=0,chanscor successful chance. char ans do { clrscr() chances=score=0 cout<<" Welcome to the High/Low game." cout<<" I will pick a random number from 0 to 100." cout<<" You must try to guess the number. What is your guess? (0 to 100) " cin>>guess if((guess<0)||(guess>100)) { cout<<"Sorry, but your guess "<<guess<<"must be from 0 to 100." } else if(guess < number) { cout<<guess<<" is low.Try a higher number." } else if(guess > number) { cout<<guess<<" is high.Try a lower number." } else//if correct number is guessed {//number is correct, and the "do" loop will end below cout<<guess<<" is correct. Congratulations!" score=chanscor*(totchan-chances) chances left ; randomize(); number=(int)(rand()%100);
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: chanscor=100/totchan; //score for each successful chance do { cout<< Sheet1 Page 2 cout<<" Your score is "<<score<<endl break } chances++ if(guess!=number) cout<<" Now you have "<<totchan-chances<<"chances left."<<endl if(chances==totchan) { cout<<" Only "<<totchan<<"chances are allowed.Better luck next time" cout<<" The actual number was "<<number<<endl break } }while (guess!=number) cout<<" Thank you for playing High/Low!" cout<<"Want to play it again? (y/n). .." cin>>ans }while(ans=='y' || ans=='Y') } Title HIGH/LOW GAME Author MOLLY ARORA Author Email molly.arora [at] rediffmail.com Description This program plays a simple game.The computer picks a random number from 0 to 100, and the user tries to gues s Category C++ » Games Hits 16172 Sheet1 Page 3 //the computer's random number //the user's guess //chanscor stores score for 1 //score calculated for number of Sheet1 Page 4...
View Full Document

This note was uploaded on 11/06/2010 for the course UBIT 411 taught by Professor Saleemelahi during the Spring '10 term at University of Karachi.

Page1 / 4

Guess the number - chanscor=100/totchan/score for each successful chance do cout<< Sheet1 Page 2 cout<<" Your score

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online