[COLOR="#FFA500"]#include <iostream> [COLOR="#008000"] // Header that defines the standard input/output stream objects[/COLOR]
#include <conio.h>[COLOR="#008000"] // for getch() - pause[/COLOR]
#include <ctime>[/COLOR] [COLOR="#008000"] // This header file contains definitions of functions to get and manipulate date and time information.[/COLOR]
[COLOR="#0000FF"][B]using namespace[/B][/COLOR] std;
[COLOR="#EE82EE"]int[/COLOR] main([COLOR="#EE82EE"]void[/COLOR])
{
[COLOR="#EE82EE"]int[/COLOR] number = [COLOR="#FFA500"]0[/COLOR];
[COLOR="#EE82EE"]int[/COLOR] random_number = [COLOR="#FFA500"]0[/COLOR];
[COLOR="#EE82EE"]int[/COLOR] number_limit = [COLOR="#FFA500"]100[/COLOR];
[COLOR="#EE82EE"]int[/COLOR] try = [COLOR="#FFA500"]0[/COLOR];
[COLOR="#EE82EE"]int[/COLOR] max_try = [COLOR="#FFA500"]5[/COLOR];
srand(([COLOR="#EE82EE"]unsigned[/COLOR])time([COLOR="#FFA500"]0[/COLOR])); [COLOR="#008000"] // Initialize random number generator[/COLOR]
cout << "[COLOR="#696969"]Welcome to guess Number ![/COLOR]" << endl; [COLOR="#008000"] // cout = Standard output Text[/COLOR]
cout << "[COLOR="#696969"]In this game you have to guess a number between 0 and 100 ![/COLOR]" << endl; [COLOR="#008000"] // endl = Inserts a new-line character[/COLOR]
cout << "[COLOR="#696969"]But that would be too easy, you have just 5 attempts. Good Luck ![/COLOR]" << endl << endl << endl;
random_number [COLOR="#0000FF"]=[/COLOR] [COLOR="#0000FF"]([/COLOR]rand[COLOR="#0000FF"]()%[/COLOR]number_limit[COLOR="#0000FF"])+[/COLOR][COLOR="#FFA500"]1[/COLOR];
for(try = 1; try <= max_try; try++)
{
if(number > 100)
cout << endl << "Your pick is to big" << number ;
if(number < 0)
cout << endl << "Your pick is to small" << number;
if (try > 1 && number > random_number)
cout << endl << "the number is <" << endl;
else if(versuche > 1 && number < random_number)
cout << endl << "the number is >" << endl;
cout << endl << "Try : " << try << endl << endl;
cout << "How is your guess ?" << endl << endl;
cin >> number;
if(number == random_number)
break;
}
if(number == random_number)
cout << endl << endl << "Winner Winner Chicken Dinner, The Number was: " << random_number << endl << endl;
else
cout << endl << endl << "Game Over you lose, The Number was: " << random_number << endl << endl;
_getch();
return 0;
}
Copyright © 2024, NextGenUpdate.
All Rights Reserved.