Techtopz is a blog on programming and tech stuff.
Techtopz is now on UpHub.
Follow us for more updates.


C++ | Generating Random Number between 2 Numbers

This is a program for generating random number between two numbers. The program takes higher limit and lower limit from user and gives a random number between the limit. The program is extendable. Go enjoy the program. Lets begin…

Program for generating random number between two numbers.

void main()
//clear the screen.
//declare variables as int.
int high,low,random;
//get the data.
cout<<"Enter higher limit:";
cout<<"Enter lower limit:";
//generate random number
random = (rand() % (high-low+1) + low);
//print the numbers
//get character


Enter higher limit:100
Enter lower limit:15

How does it work.
1. You enter the limits.
2. The number is generated and printed.

Extending it.
The program is extendable. This is a basic concept of c++ and can be used in any program. Go extend it.

1. Include ‘iostream.h’ and ‘conio.h’ and ‘stdlib.h’ files.
2. Add void main.
3. Start program by first clearing the screen.
4. Declare variables.
5. Add cout and cin to get limits.
6. Generate a number and save it in a variable.
7. Add cout to print the number.
8. Get character.

At the end
You learnt creating the C++ program for generating random number between given limit. So now enjoy the program.

Login to like the post