Wednesday, February 13, 2013

Create Game in C/C++ - Guess The Imaginary Number


In this tutorial you will learn to make a simple game in the C++. The aim of the game is, the program will imagine a number at random and players will need to guess.


Step 1


Turn on the compiler (Dev C + + in this case). Then go File >> New >> Source File.

Step 2


Write the code:

#include<iostream>using namespace std;
int main () {
srand (time (NULL));
int num1, num2;
cout << "Game - Guess The Imaginary Number" << endl;
num1 = rand ()% 100 +1;
do {
cout << "___________" << endl;
cout << "Enter a number" << endl;
cin >> num2;
if (num1 == num2)
cout << "!!! BRAVO You hit the number!!!" << endl;
else
{
if (num1 < num2)
{
cout << "The imaginary number is less" << endl;
}
else
{
cout << "The imaginary number is greater" << endl;
}
}
}
while (num1! = num2);
cin.get ();
cin.get ();
}

Step 3


Click F9, save the project. Then the program will include.


EmoticonEmoticon