C++ for Engineers and Scientists
C++ for Engineers and Scientists
4th Edition
ISBN: 9781133187844
Author: Bronson, Gary J.
Publisher: Course Technology Ptr
Bartleby Related Questions 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
Check Mark
Knowledge Booster
Background pattern image
Computer Science
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
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,