A guess number game - C++ Data Type

C++ examples for Data Type:int

Description

A guess number game

Demo Code

#include <ctime> 
#include <cstdlib> 
#include <iostream> 
#include <string> 
  
using namespace std; 
  
int main() //from  w ww .java2 s .c o  m
{ 
        // Generate unique random numbers using the current time 
        srand(time(NULL)); 
        // Get a random number between 0 and 99 
        unsigned int numberToGuess = rand() % 100; 
  
        cout << "Guess a number between 0 and 99" << endl; 
  
        unsigned int playersNumber {}; 
        cin >> playersNumber; 
  
        cout << "You guessed: " 
                << playersNumber 
                << " The actual number was: " 
                << numberToGuess 
                << endl; 
  
        return 0; 
}

Result


Related Tutorials