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

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 Answer

Want to see the step-by-step answer?

See Answer

Check out a sample Q&A here.

Want to see this answer and more?

Experts are waiting 24/7 to provide step-by-step solutions in as fast as 30 minutes!*

See Answer
*Response times vary by subject and question complexity. Median response time is 34 minutes and may be longer for new subjects.

Related Computer Science Q&A

Find answers to questions asked by student like you

Q: (Latest Revision: Apr 01, 2019) MST Problems First MST Problem:Suppose G=(V,E) is a connected undire...

A: Given (Table):According to the kruskal’s algorithm:Arrange every edge in increasing order of their w...

Q: Visual Basic. Write an expression that evaluates to true if the value of the integer variable number...

A: In visual basic we use the Mod operator to check the remainder of a division.

Q: One acre of land is equivalent to 43,560 square feet. Write a program that calculates the number of ...

A: The algorithm for the program is as follows:Accept input string as the square feetCalculate the numb...

Q: Programming in C

A: We use the bsearch function from the stdlib.h and define a compare function to return the result of ...

Q: How become a ggod programmer?

A: Good programmer:Becoming programmer is not a big thing; it is all about learning the logics of the p...

Q: Write a recursive function that computes the length of a list. For example, (mylen ‘(1 2 3 4))should...

A: The syntax for given function call (mylen’(1 2 3 4)) is of Lisp programming.For lisp program:Create ...

Q: what strategies that would attract buyers to a company's e-commerce web site

A: Strategies to attract buyers to the company e-commerce website:Offer limited time specials to new cu...

Q: example:"apple-&gt;orange-&gt;banana-&gt;pear"-&gt;NULLreturn "orange"Thanks!

A: ApproachIn the function longest(), we'll declare an integer named highestLength and assign 0 to it.N...

Q: Analyze the following code: Code 1: int number = 45;boolean even; if (number % 2 == 0) even = true;e...

A: First lets discuss about the first question. 1) In the first code we are declaring two variables num...