Write a program that reads in five whole numbers from the user. The program will calculate...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Write a program that reads in five whole numbers from the user. The program will calculate and output the following statistics about the five numbers: • • . . . The sum of all of the positive numbers (greater than zero), The sum of all of the non-positive numbers (less than or equal to zero). The sum of all five numbers. The average of all of the positive numbers (greater than zero). The average of all of the non-positive numbers (less than or equal to zero). The average of all five numbers. Note that your program must accept the five numbers in any order and cannot ask the user to enter the positive and non-positive numbers separately. You should start by calculating the sum and average of all five numbers. Be sure you get that working correctly and then move on to doing the calculations for the positive and non-positive numbers. You will need many variables to keep track of all the values, sums, and averages. Don't forget that to calculate the average of a set of numbers you sum them all up then divide by the number of values you added together. For example, if your program gets 3 positive numbers and 2 non- positive numbers, then you will divide the sum of the positive numbers by 3 to get the average and then divide the sum of the non-positive numbers by 2 to get the average of those numbers. This means you will have to keep track of how many positive numbers you read in and how many non-positive numbers you read in. Also note that you will need to write a lot of very similar looking pieces of code. Think about how to solve the problem for one or two numbers and then go from there to calculating the statistics for all five numbers. Finally, for sums, you should output just the number (e.g. 5 or 10) without any decimals (the sum of a set of integers is a sum!). However, for all averages, you must format the output to have two decimal places (even if they are both o), and round if necessary. The following represents a sample run of the program in which the user inputs on a single line "-1 1-2 2- 3" (without quotes). Note that the JUnit tests, and grading, will be very picky about exact spacing, spelling, capitalization, and number formatting. Enter five whole numbers: -1 1-2 2-3 The sum of the 2 positive numbers: 3 The sum of the 3 non-positive numbers: -6 The sum of the 5 numbers: -3 The average of the 2 positive numbers: 1.50 The average of the 3 non-positive numbers: -2.00 The average of the 5 numbers: -0.60 Enter five whole numbers: -1 -1 -2 2-3 The sum of the 1 positive number: 2 The sum of the 4 non-positive numbers: -7 The sum of the 5 numbers: -5 The average of the 1 positive number: 2.00 The average of the 4 non-positive numbers: -1.75 The average of the 5 numbers: -1.00 Write a program that reads in five whole numbers from the user. The program will calculate and output the following statistics about the five numbers: • • . . . The sum of all of the positive numbers (greater than zero), The sum of all of the non-positive numbers (less than or equal to zero). The sum of all five numbers. The average of all of the positive numbers (greater than zero). The average of all of the non-positive numbers (less than or equal to zero). The average of all five numbers. Note that your program must accept the five numbers in any order and cannot ask the user to enter the positive and non-positive numbers separately. You should start by calculating the sum and average of all five numbers. Be sure you get that working correctly and then move on to doing the calculations for the positive and non-positive numbers. You will need many variables to keep track of all the values, sums, and averages. Don't forget that to calculate the average of a set of numbers you sum them all up then divide by the number of values you added together. For example, if your program gets 3 positive numbers and 2 non- positive numbers, then you will divide the sum of the positive numbers by 3 to get the average and then divide the sum of the non-positive numbers by 2 to get the average of those numbers. This means you will have to keep track of how many positive numbers you read in and how many non-positive numbers you read in. Also note that you will need to write a lot of very similar looking pieces of code. Think about how to solve the problem for one or two numbers and then go from there to calculating the statistics for all five numbers. Finally, for sums, you should output just the number (e.g. 5 or 10) without any decimals (the sum of a set of integers is a sum!). However, for all averages, you must format the output to have two decimal places (even if they are both o), and round if necessary. The following represents a sample run of the program in which the user inputs on a single line "-1 1-2 2- 3" (without quotes). Note that the JUnit tests, and grading, will be very picky about exact spacing, spelling, capitalization, and number formatting. Enter five whole numbers: -1 1-2 2-3 The sum of the 2 positive numbers: 3 The sum of the 3 non-positive numbers: -6 The sum of the 5 numbers: -3 The average of the 2 positive numbers: 1.50 The average of the 3 non-positive numbers: -2.00 The average of the 5 numbers: -0.60 Enter five whole numbers: -1 -1 -2 2-3 The sum of the 1 positive number: 2 The sum of the 4 non-positive numbers: -7 The sum of the 5 numbers: -5 The average of the 1 positive number: 2.00 The average of the 4 non-positive numbers: -1.75 The average of the 5 numbers: -1.00
Expert Answer:
Related Book For
Computer Organization and Design The Hardware Software Interface
ISBN: 978-0124077263
5th edition
Authors: David A. Patterson, John L. Hennessy
Posted Date:
Students also viewed these mathematics questions
-
1. Write a program that translates a letter grade into a number grade. Letter grades are A, B, C, D, and F, possibly followed by + or -. Their numeric values are 4, 3, 2, 1 and 0. There is no F+ or...
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
When average total cost is at its minimum: A. Average variable cost is declining with increases in output B. Average variable cost plus average fixed cost is declining with increases in output C....
-
Dual effects on balance shed equation. Fresh Foods Group, a European food retailer that operates supermarkets in sewn countries, engaged in the following three transactions during 2008: (1) Purchased...
-
Assume Speedo International received $400,000 for long-term promissory notes that were issued on November 1. The notes pay interest on April 30 and October 31 at the annual rate of 6 percent, which...
-
What's with the Z in Z-test? In what way is it similar to a simple z or standard score?
-
Premier Building & Development, Inc., entered a listing agreement giving Sunset Gold Realty, LLC, the exclusive right to find a tenant for some commercial property. The terms of the listing agreement...
-
Prepare a memo for Photo Artistry Company identifying issues that management should consider in order to improve the profitability of the company; provide some recommendations. PHOTO ARTISTRY...
-
A textile company produces shirts and pants. Each shirt requires two square yards of cloth, and each pair of pants requires three square yards of cloth. During the next two months the following...
-
is there any way I could add a smartwatch and a glucometer to my smart home project in Cisco packet tracer?
-
ABC Insurance Company is a leading provider of property and casualty insurance. They are facing significant challenges in managing their risk exposures, particularly in relation to natural disasters...
-
ABC Inc. provided the following data for the current year: Cost of goods sold $ 4 , 6 8 0 , 0 0 0 Inventory at the beginning of the year 6 7 8 , 0 0 0 Inventory at the end of the year 5 7 0 , 0 0 0...
-
Luthan Company uses a plantwide predetermined overhead rate of $23.80 per direct labor-hour. This predetermined rate was based on a cost formula that estimated $285,600 of total manufacturing...
-
Luka bought a villa in an exclusive neighborhood at the southern part of the country. He agreed to pay 400.000 php every 3 months at 11% compounded quarterly for 5 years, and the Irst payment was due...
-
Do not focus on a single business or industry. Research how the business disciplines work together to ensure corporate/organizational strategy is implemented so the entity can move forward. Use...
-
The following information is available for Alcoy Partners for the year just ended: Sales price Fixed costs (for the year) Selling and administrative Production Variable cost (per unit) Materials...
-
The words without recourse on an indorsement means the indorser is: a. not liable for any problems associated with the instrument. b. not liable if the instrument is dishonored. c. liable personally...
-
Assume that for a given program 70% of the executed instructions are arithmetic, 10% are load/store, and 20% are branch. 1. Given this instruction mix and the assumption that an arithmetic...
-
When performing computations on sparse matrices, latency in the memory hierarchy becomes much more of a factor. Sparse matrices lack the spatial locality in the data stream typically found in matrix...
-
The importance of having a good branch predictor depends on how oft en conditional branches are executed. Together with branch predictor accuracy, this will determine how much time is spent stalling...
-
What part should the sales function play when drawing up a detailed 12 months operational marketing plan for EMA?
-
Suggest a general outline marketing planning strategy for 12 months ahead for Graham Keddie.
-
Explain the differences between marketing strategies and sales strategies.
Study smarter with the SolutionInn App