Print Friendly and PDF
// Example program
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
int main()
{
std::srand(time(0));
int randomNum = rand() %100;
//std::cout << randomNum << std::endl;
int guess;
int tries = 0;
do
{
std::cout << "Give me a number: ";
std::cin >> guess;
if ( guess>randomNum)
{
std::cout << " Number is too high, please enter a number again! ";
}
else if ( guess<randomNum)
{
std::cout << " Number is too low, please enter a number again! ";
}
else
{
std::cout << " Hurrah you got it!!! ";
}
while ( guess != randomNum );
tries = tries+1;
if ( tries==1)
{
std::cout << "It took you " << tries << " times to get it right!";
}
else
{
std::cout << "It took you " << tries << " time to get it right!";
}
}
zubairsaif

Zubair saif

A passionate writer who loves to write on new technology and programming

Post A Comment:

1 comments:

  1. Plese give a project having concept of oops including inheritance, polymophism,incapsulation, in c++ plzz sir iam waiting

    ReplyDelete