Question

c++ • Prompts the user to enter floating point numbers that represent daily sale amounts at...

c++

• Prompts the user to enter floating point numbers that represent daily sale amounts at a store o Allows the user to indicate the end of user inputs with -1

o Validates the user input for numbers greater than 0

o Stores the numbers in an array

• Determines and displays the maximum, minimum, and arithmetic mean (average) of the sale amounts

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <iostream>

using namespace std;

int main() {
    double arr[1000], sale;
    int size = 0;
    while (true) {
        cout << "Enter sales amount(-1 to exit): ";
        cin >> sale;
        if(sale == -1) break;
        if(sale < 0) {
            cout << "Error. Invalid sales amount" << endl;
        } else {
            arr[size++] = sale;
        }
    }
    // calculate maximum, minimum, and arithmetic mean
    double max = arr[0], min = arr[0], mean = 0;
    for(int i = 0; i < size; ++i) {
        if(arr[i] > max) max = arr[i];
        if(arr[i] < min) min = arr[i];
        mean += arr[i];
    }
    mean /= size;
    // display results
    cout << "Maximum sale is " << max << endl;
    cout << "Minimum sale is " << min << endl;
    cout << "Mean of sales is " << mean << endl;
    return 0;
}
Add a comment
Know the answer?
Add Answer to:
c++ • Prompts the user to enter floating point numbers that represent daily sale amounts at...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I need to Write a test program that prompts the user to enter 10 double values...

    I need to Write a test program that prompts the user to enter 10 double values into an array, calls a method to calculate the average of the numbers, and displays the average. Next, write a method that returns the lowest value in the array and display the lowest number. The program should then prompt the user to enter 10 integer values into an array, calculates the average, and displays the average. The program should have two overloaded methods to...

  • Please help C++ language Instructions Write a program that prompts the user to enter 50 integers...

    Please help C++ language Instructions Write a program that prompts the user to enter 50 integers and stores them in an array. The program then determines and outputs which numbers in the array are sum of two other array elements. If an array element is the sum of two other array elements, then for this array element, the program should output all such pairs.

  • c++ no pointers just follow instructions Write a program (array.cpp) that read positive floating point numbers...

    c++ no pointers just follow instructions Write a program (array.cpp) that read positive floating point numbers into an array of capacity 100. The program will then ask for one of three letters(A, M or S). if the user inputs something other than one of these letters, then the program should ask for that input until an A, M, or S is entered. A do-while loop should be used for this. If the user inputs an A, then the program should...

  • In Python 3, Write a program that reads a set of floating-point values. Ask the user...

    In Python 3, Write a program that reads a set of floating-point values. Ask the user to enter the values, then print: The number of values entered. The smallest of the values The largest of the values. The average of the values. The range, that is the difference between the smallest and largest values. If no values were entered, the program should display “No values were entered” The program execution should look like (note: the bold values are sample user...

  • IN C language Write a C program that prompts the user to enter a line of...

    IN C language Write a C program that prompts the user to enter a line of text on the keyboard then echoes the entire line. The program should continue echoing each line until the user responds to the prompt by not entering any text and hitting the return key. Your program should have two functions, writeStr andcreadLn, in addition to the main function. The text string itself should be stored in a char array in main. Both functions should operate...

  • write an 8086 assembly program that performs the following functions: Prompts the user to enter a set of student’s lab grades (array of 2-digit decimal numbers) and store it in the memory. Use ‘$’ sign as termination, i.e., the user enters ‘$’ at the end

    write an 8086 assembly program that performs the following functions: Prompts the user to enter a set of student’s lab grades (array of 2-digit decimal numbers) and store it in the memory. Use ‘$’ sign as termination, i.e., the user enters ‘$’ at the end of the numbers. You can assume that the maximum number of students in the lab is 20.

  • Write a Java program which allows the user to perform simple tasks on a calculator. A...

    Write a Java program which allows the user to perform simple tasks on a calculator. A series of methods allows the user to select an operation to perform and then enter operands. The first method displays a menu, giving the user the choice of typing in any one of the following: +, -, *, /, or % representing the usual arithmetic operators (Each operation should be done on numbers negative(-) to positive(+), positive(+) to negative(-), negative(-) to negative(-), and positive(+)...

  • write a c program for the above Write a program which prompts the user to enter...

    write a c program for the above Write a program which prompts the user to enter three integers (data type int) and then calculates the arithmetic average as a decimal number and prints the value with two decimal digits. If you have time also calculate and print the harmonic mean of the same numbers according to the following formula: 3. PT harmonic _mean-1 1 22x (Test with integer values of 4, 7, and 8. You may submit one program per...

  • Write a C program that prompts the user to enter a series of integers that represent...

    Write a C program that prompts the user to enter a series of integers that represent a coded message. I have given you the decoder program so that you can see how it is written using array notation. Your assignment is to convert the code to a program that uses only pointers and pointer math. Your program must use pointer notation and pointer math (i.e. no array index notation other than in the declaration section, no arrays of pointers and...

  • C# programming Create an application that prompts the user for a storm windspeed in mph, then...

    C# programming Create an application that prompts the user for a storm windspeed in mph, then determines the correct typhoon category. The program must run all test cases of storm windspeed in one execution. Use a sentinel value to terminate the program. Do not assume a specific number of inputs. Determine the maximum storm windspeed value input. Note that the maximum must be evaluated within your program. You MAY NOT use C built in function. Output screenshot must include the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT