iqramehmood586 iqramehmood586
  • 21-05-2021
  • Computers and Technology
contestada

Write a c++ program that generates three random numbers. The first number should be between 0-30, the second number should be between 30-60 and the third number should be between 60-90.

Respuesta :

tonb
tonb tonb
  • 21-05-2021

Answer:

#include <stdlib.h>

#include <time.h>  

#include <iostream>

using namespace std;

int main() {

   srand(time(NULL));

   cout << rand() % 30 << endl;

   cout << rand() % 30 + 30 << endl;

   cout << rand() % 30 + 60 << endl;

}

Explanation:

rand() returns a pseudo-random integral number in the range between 0 and RAND_MAX. By applying the modulo operator, you map that to the desired range (30 in your case), then you add an offset.

Answer Link

Otras preguntas

19. A car rental agency charges $250 per week plus $0.45 per mile to rent a car. How many miles can you travel in week for $587.50? Let x represent the number o
Which of these is not a sign that a chemical change has taken place
If it can be determined that there is a correlation between two variables then you can assume causation between one variable and the other. True or False?
50 points!! Find a poem or music lyrics that relate to the opening of "An Inspector Calls" write a paragraph explain why.
can someone help me on these two questions
Why are muscles an essential part of the circulatory system?
Select the thirteen colonies.
PLEASE HELP ASAP LIKE RN I NEED IT PLRASE REFER TO THE PIC PLEASEEE SAY RIGHT
Find the product -3.15 x -2.6 =
How did Machiavelli’s idea of a good ruler differ from that of medieval philosophers?