Escolar Documentos
Profissional Documentos
Cultura Documentos
CS PROJECT
Submitted to Manas Sir
C++ Gaming
HIGH LOW GAME (SOURCE CODE)
#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; //the computer's random number //the user's guess //chanscor stores score
chances=score=0; cout<<"Welcome to the High/Low game."<<"\n"; cout<<"I will pick a random number from 0 to 100."<<"\n"; cout<<"You must try to guess the number."<<"\n"; randomize(); number=(int)(rand()%100); chanscor=100/totchan; do { cout<<"What is your guess? (0 to 100) "<<"\n"; cin>>guess; if((guess<0)||(guess>100)) { cout<<"Sorry, but your guess "<<guess<<"must be from 0 to 100."<<"\n"; } else if(guess < number) { cout<<guess<<" is low.Try a higher number."<<"\n"; } else if(guess > number) { cout<<guess<<" is high.Try a lower number."<<"\n"; } else //if correct number is guessed //score for each successful chance
{ end below
cout<<guess<<" is correct. Congratulations!"<<"\n"; score=chanscor*(totchan-chances); number of chances left cout<<" 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!"<<"\n"; cout<<"Want to play it again? (y/n)..."; cin>>ans; }while(ans=='y' || ans=='Y'); } //score calculated for