Write a program that asks the user to enter today’s sales for five stores. The program should then display a bar chart comparing each store’s sales. Create each bar in the bar chart by displaying a row or asterisks. Each asterisk should represent $100 of sales. You must use a loop to print the bar chart. If the user enters a negative value for the sales amount, the program will keep asking the user to enter the sales amount until a positive amount is entered, You must use methods, loops and arrays for this assignment. Sample Run 1: Enter today's sale for store 1 (negative value not allowed) 1000 Enter today's sale for store 2 (negative value not allowed) 1200 Enter today's sale for store 3 (negative value not allowed) 1800 Enter today's sale for store 4 (negative value not allowed) 800 Enter today's sale for store 5 (negative value not allowed) 1900 SALES BAR CHART Store 1:********** Store 2:************ Store 3:****************** Store 4:******** Store 5:*******************

Question
Asked Feb 3, 2020
13 views

Write a program that asks the user to enter today’s sales for five stores. The program should then display a bar chart comparing each store’s sales. Create each bar in the bar chart by displaying a row or asterisks. Each asterisk should represent $100 of sales. You must use a loop to print the bar chart. If the user enters a negative value for the sales amount, the program will keep asking the user to enter the sales amount until a positive amount is entered, You must use methods, loops and arrays for this assignment. Sample Run 1: Enter today's sale for store 1 (negative value not allowed) 1000 Enter today's sale for store 2 (negative value not allowed) 1200 Enter today's sale for store 3 (negative value not allowed) 1800 Enter today's sale for store 4 (negative value not allowed) 800 Enter today's sale for store 5 (negative value not allowed) 1900 SALES BAR CHART Store 1:********** Store 2:************ Store 3:****************** Store 4:******** Store 5:*******************

check_circle

Expert Answer

Step 1

Following is the c++ program that takes as input from user sales of five stores and display the sales as a bar chart:

Approach:

  • Import the essential header.
  • Define method display to display the sales of five stores represented by asterisk where each asterisk is equal to $100 of sales.
  • Defining the main method.
  • Declaring the variables as per the requirement.
  • Using a do-while loop to validate the sales entered by the user must be greater than $0.00.
  • Prompt the user to enter the sales of five stores.
  • Call display method.

 

Step 2

Code:

#include <iostream>

 

using namespace std;

void display(int sales[5]) {

 //display message

 cout << "\n    DAILY SALES OF STORES\n    (each * = $100)\n";

 //outer for loop to itterate over the five stores

 for (int i = 0; i < 5; ++i) {

  cout << "\nStore" << i + 1<<": ";

  //inner for loop to display sales of store using asterisk

  for (int j = 0; j < sales[i]; ++j) {

   cout << "* ";

  }

 }

}

int main() {

 int Sales[5];

 //for loop to itterate over the elements of array to save the sales of five stores

 for (int i = 0; i < 5; i++) {

  // using do while loop to validate sales of Store1

  do {

   //prompt user to enter sal...

Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in

Engineering

Computer Science

Related Computer Science Q&A

Find answers to questions asked by student like you
Show more Q&A
add
question_answer

Q: in java, using the numbers 1-10 write a program that will call a method (called f) to tabulate the f...

A: Create class TabulateUse method f(int x) to compute the given mathematical polynomial.Create object ...

question_answer

Q: Explain what is meant by the term data redundancy with the help of two tables of dat

A: Data Redundancy:Data redundancy is a condition created in a database or data storage technology whic...

question_answer

Q: Calculate the total number of values that can be registered is using 32-bit ADC.

A: Total number of values registered using Analog-to-digital converterIn order to calculate the total n...

question_answer

Q: I have having some confusion as to what exactly the defintion of  "special operator in the condition...

A: The Definition of “Special Operator in The Conditional Expression” is:In the question a query based ...

question_answer

Q: Please help with the follow question in C++

A: Program Instructions:Create a function insertOnTheTop() that makes a new node and assign that node t...

question_answer

Q: What is the default folder that the ISO file will be saved to?

A: ISO:ISO file is also called an ISO image. ISO images are used for distributing large setup files, la...

question_answer

Q: Unlike third generation networks (3G), fourth generation networks (4G) carry voice and data together...

A: Spectral efficiency of cellular networks:Spectral efficiency is also known as bandwidth efficiency, ...

question_answer

Q: Question 2. Write a complete C++ program that uses a 2-dimensional array with 4 rows and 30 columns....

A: Program Instructions:In main, declare an array and call function fillarray() that fills the array wi...

question_answer

Q: In c++ i have a .dat file tha contains the following 123-45-6789 Kirk James 44.7 88.99 0.0175 124-89...

A: Overtime is calculated when working hours are more than 40. For each extra hour, the overtime pay is...