Word Count: 647
Plagiarism Percentage
15%
sources:
11% match (Internet from 20-May-2009)
1
http://www.codeguru.com/forum/showthread.php?t=399665
4% match (Internet from 14-Aug-2014)
2
http://sourcecodesworld.com/source/show.asp?ScriptID=1242
paper text:
Salmabad, Kingdom of Bahrain Object Oriented Program A CSCI531 course Project Presented to the
Faculty of the College of Computer Studies AMA International University Kingdom of Bahrain By: Abdulla
Ali Abdulhameed BH15500765 Abdulla Adel BH15500228 March 2018 Introduction C ++ is one of the most
common languages. It has been widely used in building operating systems and dealing with the computer's
hard structure from software systems and user software to embedded hardware and embedded systems to
high-performance servers and entertainment programs such as video games due to its ability to deliver
highly efficient assembly language code. C ++ is an object programming language, multiple programming
styles, fluidized, and static styles. It includes many features of high-level and low-level programming
languages. We will discuss the C++ features used in the game with examples of it from the game. Global
variable: It can be used anywhere in the code after its declaration. Const int totchan=5; Initialization of
variables: it declare and assign value to the variable in same line. int chances=0 Getting value: it take the
value from user input and store it in variable. cin>>g; Displaying value: it print the value stored in variable to
the screen. cout<<"You must try to guess the number."<<endl; Loops:it loop and replay the code until the
statement is satisfied. do { cout<<"What is your guess? (0 to 50) "; cin>>g; }while(g!=n); If else statement: It
check the condition, if its satisfied it do the statement, else it do the other statement. if((g<0)||(g>50)) {
cout<<" Sorry, but your guess "<<g<<"must be from 0 to 50."; } else if( g < n) { 1
cout<<
g<<" is low.Try a higher number."; } The game The concept of the game is, in the begging the computer will
choose a random number, then the user need to try to guess the number, if the entered number is lower
than the chosen number, it will show massage that tells the number guessed is lower, then if the entered
number is higher than the chosen number, it will show the number guessed is higher, and the user is having
7 chances only, if he failed to guess the number it will be one less until it become 0 chance. Here is the
code for the game:
#include<iostream> #include<conio.h> #include< stdlib .h> using 1
namespace std; const int totchan= 5; int main() { int n; //the random
number chosen by computer int g; //user guess int
chances=0,score=0,chanscor; char ans; do
//loop the game if user choose yes {
chances=score=0; cout<<" Welcome to the guess the number game."<<endl; 1
cout<<" I will choose a number from 0 to 50."<<endl; cout<<" You need to
guess the number."<<endl; n =(int)(rand()% 50); random number
chanscor=100/totchan; do
//computer choose //it count the score {
cout<<" What is your guess? (0 to 50) "; cin>> g; if(( g <0)||( g >100)) { 2
cout<<" Sorry, but your guess "<<g<<"must be from 0 to 50."; } else if( g < n) {
cout<<g<<" is low.Try a higher number."; } else if( g > n) { cout<<g<<" is high.Try a
lower number."; } else { //if the number is correct, it end the loop cout<< g<<" is
correct. Congratulations!"; score=chanscor*(totchan-chances); //it calculate the
score for
the user
cout<<" Your score is "<<score<<endl; break; } chances++; if( g!=n) 1
cout<<" 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 "<<n <<endl; break; } }while (g!=n);
cout<<"
Thank you for playing guess the number game!"<<endl;
cout<<" Want to play it again? (y/n)..."<<endl; cin>>ans; }while(ans=='y' || 1
ans=='Y');
} Reference: ? Stroustrup, Bjarne (1997). "1". The C++ Programming Language (Third ed.). ISBN 0-201-
88954-4. OCLC 59193992. ? Sutter, Herb; Alexandrescu, Andrei (2004). C++ Coding Standards: 101
Rules, Guidelines, and Best Practices. Addison-Wesley ? Mycroft, Alan (2013). "C and C++ Exceptions |
Templates" (PDF). Cambridge Computer Laboratory - Course Materials 2013-14. Retrieved 30 August
2016. ? Alexandrescu, Andrei; Sutter, Herb (2004). C++ Design and Coding Standards: Rules and
Guidelines for Writing Programs. Addison-Wesley. ISBN 0-321-11358-6. ? Information Technology Industry
Council (15 October 2003). Programming languages – C++(Second ed.). Geneva: ISO/IEC. 14882:2003(E).