Welcome

Hi! This blog is for beginners of c++ and java .You can check and pick codes for your programming assignments. This will also help you to understand the concepts of these programming languages. Its all about programming.

If Else Practice (Random numbers)

Wednesday, May 18, 2011

#include <iostream.h>
#include <conio.h>
#include <stdio.h>
int main() {
    int number=0;
    int rand_number=0;
    clrscr();
    cout << "Enter Number " ;
    cin >> number;
    rand_number = rand();    // rand() is a C++ function that generates random numbers
       cout << "Random number = " << rand_number << endl;

       if (number == rand_number)
        cout << "Congrats! you won the game";
     else
        cout << "Oops! You lose the Game.";

    getch();
    return 0;
}