Monday 21, May 2012
Welcome Guest, Register | Login  
      Home    |    Tutorials    |    Free Ebooks    |    Free Scripts    |    Articles    |    Blog     |    About Us    |    Contact Us

  Number guess game using c++

Here is a simple number guess game program written in c++. User will enter his guess and program will match this number with a random generated number and prints the results on screen.
Cut & Paste Script
#include<iostream.h>
#include<stdlib.h>
#include<time.h>
void main()
{
    srand(time(0));
    char ch;
    int r;
    int n,tt;

    do
    {
        tt = 0;
        r = rand()%1024;
        for(;;)
        {
            tt++;

            cout  <<"Guess number between 0 - 1023 : ";
            cin >> n;
            if(n == r)
            {
                cout <<"\nYour Guess is Correct\n";
                cout <<"Total Turns = "<<tt<<endl;
                break;
            }

            if(n < r)
            {
                cout <<"Your Guess is Less\n"<<endl;
            }
            if(n > r)
            {
                cout <<"Your Guess is More\n"<<endl;
            }
        }


    cout <<"To play again Press p  :  ";
    cin >> ch;
    }while(ch == 'p');
}

Output:
Guess number between 0 - 1023 : 512
Your Guess is Less

Guess number between 0 - 1023 : 768
Your Guess is More

Guess number between 0 - 1023 : 640
Your Guess is Less

Guess number between 0 - 1023 : 704
Your Guess is More

Guess number between 0 - 1023 : 672
Your Guess is More

Guess number between 0 - 1023 : 656
Your Guess is Less

Guess number between 0 - 1023 : 664
Your Guess is More

Guess number between 0 - 1023 : 660
Your Guess is More

Guess number between 0 - 1023 : 658
Your Guess is More

Guess number between 0 - 1023 : 657

Your Guess is Correct
Total Turns = 10
To play again Press p  :n
Press any key to continue
 
   
     RELATED SCRIPTS
 
Creating an abstract class using C++
Here is the source code for an abstract class in C++....more »
Category : C++ Programs Hits : 479
   
program to print a rectangle of "*"
The following program forms a rectangle of "*"
(Length and width of rectangle entered by user)...more »
Category : C++ Programs Hits : 992
   
printing current date and time using c++
An example to print current date and time using c++....more »
Category : C++ Programs Hits : 684
   
Sorting numbers using selection sort in c++
Here is a program example to read a list of integer numbers from keybord and prints them in sorted order. This program is using selection sort to order the integers....more »
Category : C++ Programs Hits : 1492
   
Finding number of bytes in a file using c++
Here is a program example to find the number of bytes in a text file using c++....more »
Category : C++ Programs Hits : 835
   
   
SCRIPT CATEGORIES
 
  C Programs
C Programs scripts
  C++ Programs
C++ Programs scripts
  Java Programs
Java Programs scripts
  JavaScript Examples
JavaScript Examples scripts
  PHP Examples
PHP Examples scripts
  VBScript Examples
VBScript Examples scripts
 
 
 
POPULAR E-BOOKS
 
Download Linux Internals (to the power of -1)  Ebook Linux Internals (to the power of -1)
   
Download C Sharp Beginners Ebook C Sharp Beginners
   
Download  100 000  Worth of the Biggest Money Making Secrets Ever Revealed Ebook 100 000 Worth of the Biggest Money Making Secrets Ever Revealed
   
Download Art Gallery Theorems and Algorithms  Ebook Art Gallery Theorems and Algorithms
   
Download Bringing Design to Software  Ebook Bringing Design to Software
   
 
Studiesinn.com © 2012 All Rights Reserved.
Website Designed & Developed by TechXprtz