VB icon

Maths Game and Word Game

Email
Submitted on: 4/29/2016 10:01:33 AM
By: A.Aadhitya 
Level: Advanced
User Rating: By 1 Users
Compatibility: C++ (general)
Views: 1712
 
     to develop students knowledge
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// Name: Maths Game and Word Game
// Description:to develop students knowledge
// By: A.Aadhitya
//**************************************

/* This project "GAME" was developed by
Master A.AADHITYA studying in class XI in
KV A.F.S thanjavur of the batch 2015-16.
This project is to develop the knowledge
of the students in both maths and the
general knowledge the students of all
classes from I to XII can play this
game*/
/*The maths game consists of four
different games:
1) addition game,
2) subtraction game,
3) multiplycation game,
4) division game.
*/
/*The word game has many countries name
the computer will give you 15 tries you
must find the countries name within it
or the computer will give you the correct
name*/
#include<iostream.h>//file includes
#include<conio.h>//file includes
#include<stdio.h>//file includes
#include<string.h>//file includes
#include<stdlib.h>//file includes
#include<math.h>//file includes
#include<process.h>//file includes
#include<ctype.h>//file includes
#include<time.h>//file includes
typedef int game;//this is to create a new data type
typedef char character;//this is to create a new data type
const int MAXLENGTH=80;//this is a constant integer variable
const int MAX_TRIES=15;//this is a constant integer variable
const int MAXROW=7;//this is a constant integer variable
int letterFill (char, char[], char[]);//this is a function 1 prototype
void initUnknown (char[], char[]);//this is a function 2 prototype
void main()
{//main block open
	 clrscr();//this function clear the screen
	 game username,password,inuser=123,inpassword=111,game;//variable decleration
	 cout<<"Computer Science Project"<<endl;//heading
	 cout<<"~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
	 cout<<"GAMES"<<endl;//sub heading
	 cout<<"~~~~~"<<endl;
	 cout<<"Done by A.AADHITYA of class XI"<<endl;
	 cout<<"Enter Username"<<endl;
	 cin>>username;//to get the user name
	 if(username==inuser)
		{//if block 1 open
		 /* this if block 1
		 and else block 1 to
		 check the user name
		 is correct or not*/
		 cout<<"username correct"<<endl;
		}//if block 1 close
	 else
		{//else block 1 open
		 cout<<"wrong username"<<endl;
		 exit(0);//function for exit
		}//else block 1 close
	 cout<<"Enter Password"<<endl;
	 cin>>password;//to get the password
	 if(password!=inpassword)
		 {//if block 2 open
		 /* this if block 1
		 and else block 1 to
		 check the password
		 is correct or not*/
		 exit(0);//function to exit
		 }//if block 2 close
		 do
		 {//do while loop 1 open
		 /*do while does not end in
		 this case because for displaying
		 the option again and again*/
		 Main:
		 cout<<"Select your game"<<endl;
		 cout<<"1 for maths game"<<endl;
		 cout<<"2 for word game"<<endl;
		 cout<<"3 for exit"<<endl;
		 cin>>game;
		 switch(game)
		 {//switch case 1 open
		 case 1://case for maths game
		 cout<<"Maths Game"<<endl;//heading
		 cout<<"~~~~~~~~~~"<<endl;
		 character x;
		 G:
		 cout<<"+ for addition game"<<endl;
		 cout<<"- for subtraction game"<<endl;
		 cout<<"* for multiplication game"<<endl;
		 cout<<"/ for division game"<<endl;
		 cout<<"# for Exit"<<endl;
		 cout<<"M Goto main menu"<<endl;
		 cout<<"Select your option"<<endl;
		 cin>>x;
		 switch(x)
			{//switch case 2 open
			case 'M'://case for main menu
			goto Main;
			case '+'://case for addition game
			/* In the addition game you must add the
			given numbers and enter the answer the
			computer will check the answer if it
			is correct the computer will give a
			point or if the answer is wrong the
			computer will give the correct answer
			it will not give any point*/
			A:
			cout<<"Addition Game"<<endl; //heading
			cout<<"~~~~~~~~~~~~~"<<endl;
			char z;
			cout<<"Select your level"<<endl;
			cout<<"E for Easy"<<endl;
			cout<<"M for Medium"<<endl;
			cout<<"H for Hard"<<endl;
			cout<<"I for instruction"<<endl;
			cout<<"Z for Exit"<<endl;
			cout<<"Enter your choice"<<endl;
			cin>>z;
			switch(z)
				{//switch case 3 open
				case 'E'://case for easy level
				int a,b,c,d,e=0,f=0,n,g=0;
				cout<<"How many questions you want"<<endl;
				cin>>n;
				for(int i=1;i<=n;i++)
				{//for loop 1 open
				randomize();/*this function that changes
						random value each and every
						time this is used*/
				a=random(50-1+1)+1; /*this function is to
							give random number
							between 1-50*/
				b=random(50-1+1)+1; /*this function is to
							give random number
							between 1-50*/
				g++;
				cout<<"Q"<<g<<")"<<"\n"<<a<<"+"<<b<<"\n"<<"find the answer of the no."<<endl;
				cin>>c;
				d=a+b;
				if(c==d)
					{//if block 3 open
					cout<<"Correct answer"<<endl;
					e++;
					}//if block 3 close
				else
					{//else block 2 open
					cout<<"Wrong answer"<<endl;
					cout<<a+b<<"\a"<<endl;
					f++;
					}//else block 2 close
				}//for loop 1 close
				cout<<"Correct="<<e<<endl;
				cout<<"Wrong="<<f<<endl;
				cout<<"Your score="<<e<<"/"<<n<<endl;
				cout<<"Thanks for playing"<<endl;
				break;
				case 'M'://case for medium level
				int a1,b1,c1,d1,e1=0,f1=0,n1,g1=0;
				cout<<"How many questions you want"<<endl;
				cin>>n1;
				for(int i1=1;i1<=n1;i1++)
					{//for loop 2 open
					randomize();/*this function that changes
							random value each and every
							time this is used*/
					a1=random(100-1+1)+1; /*this function is to
								give random number
								between 1-100*/
					b1=random(100-1+1)+1; /*this function is to
								give random number
								between 1-100*/
					g++;
					cout<<"Q"<<g1<<")"<<"\n"<<a1<<"+"<<b1<<"\n"<<"find the answer of the no."<<endl;
					cin>>c1;
					d1=a1+b1;
					if(c1==d1)
						{//if block 4 open
						cout<<"Correct answer"<<endl;
						e1++;
						}//if block 4 close
					else
						{//else block 3 open
						cout<<"Wrong answer"<<endl;
						cout<<a1+b1<<"\a"<<endl;
						f1++;
						}
					}//for loop 2 close
				cout<<"Correct="<<e1<<endl;
				cout<<"Wrong="<<f1<<endl;
				cout<<"Your score="<<e1<<"/"<<n1<<endl;
				cout<<"Thanks for playing"<<endl;
				break;
				case 'H'://case for hard level
				int a2,b2,c2,d2,e2=0,f2=0,n2,g2=0;
				cout<<"How many questions you want"<<endl;
				cin>>n2;
				for(int i2=1;i2<=n2;i2++)
					{//for loop 3 open
					randomize();/*this function that changes
							random value each and every
							time this is used*/
					a2=random(150-1+1)+1; /*this function is to
								give random number
								between 1-150*/
					b2=random(150-1+1)+1; /*this function is to
								give random number
								between 1-150*/
					g2++;
					cout<<"Q"<<g2<<")"<<"\n"<<a2<<"+"<<b2<<"\n"<<"find the answer of the no."<<endl;
					cin>>c2;
					d2=a2+b2;
					if(c2==d2)
						{//if block 5 open
						cout<<"Correct answer"<<endl;
						e2++;
						}//if block 5 close
					else
						{//else block 3 open
						cout<<"Wrong answer"<<endl;
						cout<<a2+b2<<"\a"<<endl;
						f2++;
						}//else block 3 close
					}//for loop 3 close
				cout<<"Correct="<<e2<<endl;
				cout<<"Wrong="<<f2<<endl;
				cout<<"Your score="<<e2<<"/"<<n2<<endl;
				cout<<"Thanks for playing"<<endl;
				break;
				case'I'://case for instruction
				cout<<"Instructions";
				cout<<"1)You will get two numbers you must";
				cout<<"find the answer as per the question";
				cout<<"you selected"<<endl;
				cout<<"2)You may select your level of game"<<endl;
				goto A;
				case'Z'://case for exit
				/* If the user needs to quit
				the programe then this case
				helps exit.*/
				exit(1);//function to exit
				break;
				}//switch case 3 close
				break;
				case '-'://case for subtraction game
				/* In the subtraction game you must
				subtract the given numbers and enter
				the answer the computer will check
				the answer if it is correct the
				computer will give a point or if
				the answer is wrong the computer
				will give the correct answer
				it will not give any point*/
				S:
				cout<<"Substraction Game"<<endl;//heading
				cout<<"~~~~~~~~~~~~~~~~~"<<endl;
				char z1;
				cout<<"Select your level"<<endl;
				cout<<"E for Easy"<<endl;
				cout<<"M for Medium"<<endl;
				cout<<"H for Hard"<<endl;
				cout<<"Z for Exit"<<endl;
				cout<<"I for instructions"<<endl;
				cout<<"Enter your choice"<<endl;
				cin>>z1;
				switch(z1)
				{//switch case 4 open
				case 'E'://case for easy level
				int a,b,c,d,e=0,f=0,n,g=0;
				cout<<"How many questions you want"<<endl;
				cin>>n;
				for(int i=1;i<=n;i++)
					{//for loop 4 open
					randomize();/*this function that changes
							random value each and every
							time this is used*/
					a=random(50-1+1)+1; /*this function is to
								give random number
								between 1-50*/
					b=random(50-1+1)+1; /*this function is to
								give random number
								between 1-50*/
					g++;
					cout<<"Q"<<g<<")"<<"\n"<<a<<"-"<<b<<"\n"<<"find the sum of the no."<<endl;
					cin>>c;
					d=a-b;
					if(c==d)
					{//if block 6 open
					cout<<"Correct answer"<<endl;
					e++;
					}//if block 6 close
					else
					{//else block 4 open
					cout<<"Wrong answer"<<endl;
					cout<<a-b<<"\a"<<endl;
					f++;
					}//else block 4 close
					}//for loop 4 close
				cout<<"Correct="<<e<<endl;
				cout<<"Wrong="<<f<<endl;
				cout<<"Your score="<<e<<"/"<<n<<endl;
				cout<<"Thanks for playing"<<endl;
				break;
				case 'M'://case for medium level
				int a1,b1,c1,d1,e1=0,f1=0,n1,g1=0;
				cout<<"How many questions you want"<<endl;
				cin>>n1;
				for(int i1=1;i1<=n1;i1++)
					{//for loop 5 open
					randomize();/*this function that changes
							random value each and every
							time this is used*/
					a1=random(100-1+1)+1; /*this function is to
								give random number
								between 1-100*/
					b1=random(100-1+1)+1; /*this function is to
								give random number
								between 1-100*/
					g++;
					cout<<"Q"<<g1<<")"<<"\n"<<a1<<"-"<<b1<<"\n"<<"find the sum of the no."<<endl;
					cin>>c1;
					d1=a1-b1;
					if(c1==d1)
					{//if block 7 open
					cout<<"Correct answer"<<endl;
					e1++;
					}//if block 7 close
					else
					{//else block 5 open
					cout<<"Wrong answer"<<endl;
					cout<<a1-b1<<"\a"<<endl;
					f1++;
					}//else block 5 close
					}//for loop 5 close
				cout<<"Correct="<<e1<<endl;
				cout<<"Wrong="<<f1<<endl;
				cout<<"Your score="<<e1<<"/"<<n1<<endl;
				cout<<"Thanks for playing"<<endl;
				break;
				case 'H'://cals for hard level
				int a2,b2,c2,d2,e2=0,f2=0,n2,g2=0;
				cout<<"How many questions you want"<<endl;
				cin>>n2;
				for(int i2=1;i2<=n2;i2++)
					{//for loop 6 open
					randomize();/*this function that changes
							random value each and every
							time this is used*/
					a2=random(150-1+1)+1; /*this function is to
								give random number
								between 1-150*/
					b2=random(150-1+1)+1; /*this function is to
								give random number
								between 1-150*/
					g2++;
					cout<<"Q"<<g2<<")"<<"\n"<<a2<<"-"<<b2<<"\n"<<"find the sum of the no."<<endl;
					cin>>c2;
					d2=a2-b2;
					if(c2==d2)
					{//if block 8 open
					cout<<"Correct answer"<<endl;
					e2++;
					}//if block 8 close
					else
					{//else block 5 open
					cout<<"Wrong answer"<<endl;
					cout<<a2-b2<<"\a"<<endl;
					f2++;
					}//else block 5 close
					}//for loop 6 close
			 cout<<"Correct="<<e2<<endl;
			 cout<<"Wrong="<<f2<<endl;
			 cout<<"Your score="<<e2<<"/"<<n2<<endl;
			 cout<<"Thanks for playing"<<endl;
			 break;
			 case'I'://case for instruction
			 cout<<"Instructions";
			 cout<<"1)You will get two numbers you must";
			 cout<<"find the answer as per the question";
			 cout<<"you selected"<<endl;
			 cout<<"2)You may select your level of game"<<endl;
			 goto S;
			 case 'Z'://case for exit
			 /* If the user needs to quit
			 the programe then this case
			 helps exit.*/
			 exit(1);//function to exit
			 break;
			 }//switch case 4 close
			 break;
			 case '*'://case for multiplication game
			 /* In the multiplication game you must
			 the multiply the given numbers and
			 enter the answer the computer will
			 check the answer if it is correct
			 the computer will give a point or
			 if the answer is wrong the
			 computer will give the correct
			 answer it will not give any point*/
			 M:
			 cout<<"Multiplication Game"<<endl; //heading
			 cout<<"~~~~~~~~~~~~~~~~~~~"<<endl;
			 char z2;
			 cout<<"Select your level"<<endl;
			 cout<<"E for Easy"<<endl;
			 cout<<"M for Medium"<<endl;
			 cout<<"H for Hard"<<endl;
			 cout<<"I for instructions"<<endl;
			 cout<<"Z for Exit"<<endl;
			 cout<<"Enter your choice"<<endl;
			 cin>>z2;
			 switch(z2)
			 {//switch case 5 open
			 case 'E'://case for easy level
			 int a,b,c,d,e=0,f=0,n,g=0;
			 cout<<"How many questions you want"<<endl;
			 cin>>n;
			 for(int i=1;i<=n;i++)
				{//for loop 7 open
				randomize();/*this function that changes
						random value each and every
						time this is used*/
				a=random(20-1+1)+1; /*this function is to
							give random number
							between 1-20*/
				b=random(15-1+1)+1; /*this function is to
							give random number
							between 1-15*/
				g++;
				cout<<"Q"<<g<<")"<<"\n"<<a<<"*"<<b<<"\n"<<"find the sum of the no."<<endl;
				cin>>c;
				d=a*b;
				if(c==d)
					{//if block 9 open
					cout<<"Correct answer"<<endl;
					e++;
					}//if block 9 close
				else
					{//else block 6 open
					cout<<"Wrong answer"<<endl;
					cout<<a*b<<"\a"<<endl;
					f++;
					}//else block 6 close
				}//for loop 7 close
				cout<<"Correct="<<e<<endl;
				cout<<"Wrong="<<f<<endl;
				cout<<"Your score="<<e<<"/"<<n<<endl;
				cout<<"Thanks for playing"<<endl;
				break;
				case 'M'://case for medium level
				int a1,b1,c1,d1,e1=0,f1=0,n1,g1=0;
				cout<<"How many questions you want"<<endl;
				cin>>n1;
				for(int i1=1;i1<=n1;i1++)
					{//for loop 8 open
					randomize();/*this function that changes
							random value each and every
							time this is used*/
					a1=random(30-1+1)+1; /*this function is to
								give random number
								between 1-30*/
					b1=random(25-1+1)+1; /*this function is to
								give random number
								between 1-25*/
					g++;
					cout<<"Q"<<g1<<")"<<"\n"<<a1<<"*"<<b1<<"\n"<<"find the sum of the no."<<endl;
					cin>>c1;
					d1=a1*b1;
					if(c1==d1)
						{//if block 10 open
						cout<<"Correct answer"<<endl;
						e1++;
						}//if block 10 close
					else
						{//else block 7 open
						cout<<"Wrong answer"<<endl;
						cout<<a1*b1<<"\a"<<endl;
						f1++;
						}//else block 7 close
					}//for loop 8 close
				cout<<"Correct="<<e1<<endl;
				cout<<"Wrong="<<f1<<endl;
				cout<<"Your score="<<e1<<"/"<<n1<<endl;
				cout<<"Thanks for playing"<<endl;
				break;
				case 'H'://case for hard level
				int a2,b2,c2,d2,e2=0,f2=0,n2,g2=0;
				cout<<"How many questions you want"<<endl;
				cin>>n2;
				for(int i2=1;i2<=n2;i2++)
					{//for loop 9 open
						randomize();/*this function that changes
								random value each and every
								time this is used*/
						a2=random(40-1+1)+1; /*this function is to
									give random number
									between 1-40*/
						b2=random(35-1+1)+1; /*this function is to
									give random number
									between 1-35*/
						g2++;
						cout<<"Q"<<g2<<")"<<"\n"<<a2<<"*"<<b2<<"\n"<<"find the sum of the no."<<endl;
						cin>>c2;
						d2=a2*b2;
						if(c2==d2)
							{//if block 11 open
							cout<<"Correct answer"<<endl;
							e2++;
							}//if block 11 close
						else
							{//else block 8 open
							cout<<"Wrong answer"<<endl;
							cout<<a2*b2<<"\a"<<endl;
							f2++;
							}//else block 8 close
					}//for loop 9 close
				cout<<"Correct="<<e2<<endl;
				cout<<"Wrong="<<f2<<endl;
				cout<<"Your score="<<e2<<"/"<<n2<<endl;
				cout<<"Thanks for playing"<<endl;
				break;
				case'I'://case for instruction
				cout<<"Instructions";
				cout<<"1)You will get two numbers you must";
				cout<<"find the answer as per the question";
				cout<<"you selected"<<endl;
				cout<<"2)You may select your level of game"<<endl;
				goto M;
				case 'Z'://case for exit
				/* If the user needs to quit
				the programe then this case
				helps exit.*/
				exit(1);//function for exit
				break;
				}//switch case 5 close
				break;
				case '/'://case for division game
				/* In the division game you must
				divide the given numbers and enter
				the answer the computer will check
				the answer if it is correct the
				computer will give a point or if
				the answer is wrong the computer
				will give the correct answer
				it will not give any point*/
				D:
				cout<<"Division Game"<<endl; //heading
				cout<<"~~~~~~~~~~~~~"<<endl;
				char z3;
				cout<<"Select your level"<<endl;
				cout<<"E for Easy"<<endl;
				cout<<"M for Medium"<<endl;
				cout<<"H for Hard"<<endl;
				cout<<"I for instructions"<<endl;
				cout<<"Z for Exit"<<endl;
				cout<<"Enter your choice"<<endl;
				cin>>z3;
				switch(z3)
				{//switch case 6 open
				case'I'://case for instruction
				cout<<"Instructions";
				cout<<"1)You will get two numbers you must";
				cout<<"find the answer as per the question";
				cout<<"you selected"<<endl;
				cout<<"2)You may select your level of game"<<endl;
				goto D;
				case 'E'://case for easy level
				int a,b,c,d,e=0,f=0,n,g=0;
				cout<<"How many questions you want"<<endl;
				cin>>n;
				for(int i=1;i<=n;i++)
					{//for loop 10 open
					randomize();/*this function that changes
							random value each and every
							time this is used*/
					a=random(20-1+1)+1; /*this function is to
								give random number
								between 1-20*/
					b=random(15-1+1)+1; /*this function is to
								give random number
								between 1-15*/
					g++;
					cout<<"Q"<<g<<")"<<"\n"<<a<<"/"<<b<<"\n"<<"find the sum of the no."<<endl;
					cin>>c;
					d=a/b;
					if(c==d)
						{//if block 12 open
						cout<<"Correct answer"<<endl;
						e++;
						}//if block 12 close
					else
						{//else block 9 open
						cout<<"Wrong answer"<<endl;
						cout<<a/b<<"\a"<<endl;
						f++;
						}//else block 9 close
					}//for loop 10 open
				cout<<"Correct="<<e<<endl;
				cout<<"Wrong="<<f<<endl;
				cout<<"Your score="<<e<<"/"<<n<<endl;
				cout<<"Thanks for playing"<<endl;
				break;
				case 'M'://case for medium level
				int a1,b1,c1,d1,e1=0,f1=0,n1,g1=0;
				cout<<"How many questions you want"<<endl;
				cin>>n1;
				for(int i1=1;i1<=n1;i1++)
					{//for loop 11 open
					randomize();/*this function that changes
							random value each and every
							time this is used*/
					a1=random(30-1+1)+1; /*this function is to
								give random number
								between 1-30*/
					b1=random(25-1+1)+1; /*this function is to
								give random number
								between 1-25*/
					g++;
					cout<<"Q"<<g1<<")"<<"\n"<<a1<<"/"<<b1<<"\n"<<"find the sum of the 	no."<<endl;
					cin>>c1;
					d1=a1/b1;
					if(c1==d1)
						{//if block 13 open
						cout<<"Correct answer"<<endl;
						e1++;
						}//if block 13 close
					else
						{//else block 9 open
						cout<<"Wrong answer"<<endl;
						cout<<a1/b1<<"\a"<<endl;
						f1++;
						}//else block 9 close
					}//for loop 11 close
				cout<<"Correct="<<e1<<endl;
				cout<<"Wrong="<<f1<<endl;
				cout<<"Your score="<<e1<<"/"<<n1<<endl;
				cout<<"Thanks for playing"<<endl;
				break;
				case 'H'://case for hard level
				int a2,b2,c2,d2,e2=0,f2=0,n2,g2=0;
				cout<<"How many questions you want"<<endl;
				cin>>n2;
				for(int i2=1;i2<=n2;i2++)
					{//for loop 12 open
					randomize();/*this function that changes
							random value each and every
							time this is used*/
					a2=random(40-1+1)+1; /*this function is to
								give random number
								between 1-40*/
					b2=random(35-1+1)+1; /*this function is to
								give random number
								between 1-35*/
					 g2++;
					cout<<"Q"<<g2<<")"<<"\n"<<a2<<"/"<<b2<<"\n"<<"find the sum of the no."<<endl;
					cin>>c2;
					d2=a2/b2;
					if(c2==d2)
						{//if block 14 open
						cout<<"Correct answer"<<endl;
						e2++;
						}//if block 14 close
					else
						{//else block 10 open
						cout<<"Wrong answer"<<endl;
						cout<<a2/b2<<"\a"<<endl;
						f2++;
						}//else block 10 close
					}//for loop 12 close
				cout<<"Correct="<<e2<<endl;
				cout<<"Wrong="<<f2<<endl;
				cout<<"Your score="<<e2<<"/"<<n2<<endl;
				cout<<"Thanks for playing"<<endl;
				break;
				case 'Z'://case for exit
				/* If the user needs to quit
				the programe then this case
				helps exit.*/
				exit(1);//function for exit
				break;
				}//switch case 6 close
				break;
				case '#'://case for exit
				/* If the user needs to quit
				the programe then this case
				helps exit.*/
				exit(1);//function for exit
				break;
				}
				goto G;
				case 2://case for word game
				char unknown [MAXLENGTH];
				char letter;
				int num_of_wrong_guesses=0;
				char word[MAXLENGTH];
				char words[][MAXLENGTH] =
				{//the list of countries for the guessing
				"india",
				"pakistan",
				"nepal",
				"malaysia",
				"philippines",
				"australia",
				"iran",
				"srilanka",
				"america",
				"indonesia",
				"france",
				"spain",
				"norway",
				"egypt",
				"england",
				"afghanistan",
				"albania",
				"algeria",
				"austria",
				"bolivia",
				"brazil",
				"burma",
				"canada",
				"chile",
				"ethiopia",
				"fiji",
				"finland",
				"france",
				"germany",
				"hungary",
				"iran",
				"iraq",
				"ireland",
				"iceland",
				"japan",
				"italy",
				"korea",
				"kenya",
				"kuwait",
				"malaysia",
				"mexio",
				"nepal",
				"new zealand",
				"nigeria",
				"oman",
				"peru",
				"switzerland",
				"zambia",
				"zimbabwe",
				"yemen",
				"vietnam",
				"ukraine",
				"turkey",
				"thailand",
				"sweden",
				"romania",
				"poland",
				"panama",
				"norway",
				"maldives",
				"madagascar",
				"libya",
				"rome",
				"indonesia",
				"czech republic",
				"cuba",
				"china",
				"butan",
				"belgium",
				"argentina",
				"armenia",
				"angola",
				"bahamas",
				"bahrain"
				};
				randomize();/*this function that changes
						random value each and every
						time this is used*/
				int n=random(73);
				strcpy(word,words[n]);/*this function copy
							the second string
							into first string*/
				initUnknown(word, unknown);//calling of function 2
				cout<<"Word game"<<endl; //heading
				cout<<"~~~~~~~~~"<<endl;
				cout << "\n\n..... GUESS A COUNTRY NAME...";
				cout << "\n\nEACH LETTER IS REPRESENTED BY 'STAR' !!";
				cout << "\n\nYou have to type only one letter in one try";
				cout << "\n\nYou have ONLY " << MAX_TRIES << " tries to try and guess the word.";
				cout << "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
				while (num_of_wrong_guesses < MAX_TRIES)
					{//while loop 1 open
					cout << "\n\n" << unknown;
					cout << "\n\nGuess a letter: ";
					cin >> letter;
					if (letterFill(letter, word, unknown)==0)//calling of function 1
						{//if block 15 open
						cout << endl << "Whoops! That letter isn't in there!" << endl;
						num_of_wrong_guesses++;
						}//if block 15 close
					else
						{//else block 11 open
						cout << endl << "You found a letter! Isn't that exciting!" << endl;
						}//else block 11 close
					cout << "You have " << MAX_TRIES - num_of_wrong_guesses;
					cout << " guesses left." << endl;
					if (strcmp(word, unknown) == 0)
						{//if block 16 open
						cout << "\n\n\n\t\tYeah! You got it!";
						cout << "\n\t\t !!!!THE WORD IS "<< word<<endl;
						cout << "\n\t\t!!!! YOU WON !!!!"<<endl;
						break;
						}//if block 16 close
					}//while loop 1 close
					if(num_of_wrong_guesses == MAX_TRIES)
						{//if block 17 open
						cout << "\n\t\t\t\tSorry, you lose..." << endl;
						cout << "\t\t\t\tThe word was : " << word << endl;
						}//if block 17 close
						getch();
						break;
						case 3://case for exit
						{
						/* If the user needs to quit
						the programe then this case
						helps exit.*/
						exit(0);//function for exit
						}
						default:
						/* this is to give message when
						the user of the programe give
						wrong input*/
						cout<<"Wrong choice"<<endl;
						break;
		 }//switch case 1 close
	 getch();
		 }//do while loop close
		 while(1);
 }//main block close
	int letterFill (char guess, char secretword[], char guessword[])//function 1 decleration
		{//function 1 decleration open
		int i;
		int matches=0;
		for (i = 0; secretword[i]!='\0'; i++)
			{//for loop 13 open
			if (guess == guessword[i])
				{//if block 17 open
				return 0;
				}//if block 17 close
			if (guess == secretword[i])
				{//if block 18 open
				guessword[i] = guess;
				matches++;
				}//if block 18 close
			}//for loop 14 close
		return matches;
		}//function 1 decleration close
		void initUnknown (char word[], char unknown[])//function 2 decleration
			{//function 2 decleration open
			int i;
			int length = strlen(word);
			for (i = 0; i < length; i++)
				{//for loop 15 open
				unknown[i]='*';
				}//for loop 15 close
			unknown[i]='\0';
			}//function 2 decleration close


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Advanced category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.