{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

guess the number - chanscor=100/totchan/score for each...

Info icon This 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);
Image of page 1

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

View Full Document Right Arrow Icon
Image of page 2
Image of page 3

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

View Full Document Right Arrow Icon
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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern