Write a program in c++ to generate a random number between 1 - 100, and then display which quartile the number falls in. First quartile is 1 - 25 Second quartile is 26 - 50 Third quartile is 51 - 75 Fourth quartile is 76 - 100 The following program shows how to get a random integer between 1 - 100. Use the code as an example for your own program. SAMPLE PROGRAM// This program displays a random number between 1 - 100#include <iostream> // for input and output#include <cstdlib>  // for rand() and srand()#include <ctime>    // for time()using namespace std;int main(){    //constantsconst int MIN_VALUE = 1;const int MAX_VALUE = 100;//get system time and seed random number generatorunsigned seed = time(0);srand(seed);//get random number between 1 - 100int num = (rand() % (MAX_VALUE - MIN_VALUE + 1)) + MIN_VALUE;cout << num << endl;return 0;} Your program should: contain header comments as shown in class display a "hello" message generate a random number between 1 - 100 display the number back to the user determine which quartile the number falls in (using any combination of if, else, and else if) display the quartile back to the user display a "goodbye" message before exiting the program

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter4: Selection Structures
Section4.3: Nested If Statements
Problem 7E
icon
Related questions
Question

Write a program in c++ to generate a random number between 1 - 100, and then display which quartile the number falls in.

  • First quartile is 1 - 25
  • Second quartile is 26 - 50
  • Third quartile is 51 - 75
  • Fourth quartile is 76 - 100

The following program shows how to get a random integer between 1 - 100. Use the code as an example for your own program.


SAMPLE PROGRAM
// This program displays a random number between 1 - 100
#include <iostream> // for input and output
#include <cstdlib>  // for rand() and srand()
#include <ctime>    // for time()
using namespace std;

int main()
{
    //constants
const int MIN_VALUE = 1;
const int MAX_VALUE = 100;

//get system time and seed random number generator
unsigned seed = time(0);
srand(seed);

//get random number between 1 - 100
int num = (rand() % (MAX_VALUE - MIN_VALUE + 1)) + MIN_VALUE;
cout << num << endl;

return 0;
}

Your program should:

  • contain header comments as shown in class
  • display a "hello" message
  • generate a random number between 1 - 100
  • display the number back to the user
  • determine which quartile the number falls in (using any combination of if, else, and else if)
  • display the quartile back to the user
  • display a "goodbye" message before exiting the program

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 5 steps with 3 images

Blurred answer
Knowledge Booster
Function Arguments
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr