Write a program that prompts the user to input five decimal numbers. The program should then add the five decimal numbers, convert the sum to the nearest integer, and print the result.Use the static_caststatement with an appropriate equation to convert the sum to an integer. Compile and run your program with the following test data:Case 1: Input: 5.1, 5.1, 5.1, 5.1, 5.1. Expected Output: 26.Case 2: Input: 5.0, 5.0, 5.0, 5.0, 5.0. Expected Output: 25

Answers

Answer 1

Answer:

#include <iostream>

#include <cmath>

using namespace std;

int main()

{

   double num1, num2, num3, num4, num5, sum = 0;

   cout << "Input: ";

   cin >> num1 >> num2 >> num3 >> num4 >> num5;

   

   sum = num1 + num2 + num3 + num4 + num5;

   cout << "Output: " << static_cast<int>(round(sum)) << endl;

   return 0;

}

Explanation:

Include cmath to use the round function

Declare the variables

Get the five numbers from the user

Sum them and assign the result to the sum

Round the sum using the round function, and convert the sum to an integer using static_cast statement

Print the sum


Related Questions

Write a script called checkLetter.sh Review Greeting.sh for an example. Use a read statement and ask user to "Enter A, B, or C: "

If user types A, echo "You entered A"
If user types B, echo " You entered B"
If user types C, echo " You entered C"
Use the case structure to test the user’s string.
If user types any letter from lower case ‘a through z’ or upper case ‘D through Z’, echo "You did not enter A, B, or C".

Answers

Answer:

The code is given as below: The input and output is as given for one case.

Explanation:

echo -e "Enter A, B or C : \c" #Printing the line on the screen

read -rN 1 test #read the character in the variable test

echo

case $test in #Setting up the case structure for variable test

[[:lower:]] ) #checking all lower case letters

echo You did not enter A, B or C;;

[D-Z] ) #checking upper case letters from D to Z

echo You did not enter A, B or C;;

A ) #Condition to check A

echo You entered A;;

B ) #Condition to check B

echo You entered B;;

C ) #Condition to check C

echo You entered C;;

esac #Exiting the case structure

Other Questions
One way in which Frederick Douglass, William Lloyd Garrison, and Harriet Tubman are similar is that they all supported the ...a. passage of Black Codesb. abolitionist movementc. nullification theory of States rightsd. plantation system in the South How does the characterization of Easton shapethe theme that life's problems and the passageof time can change people in unexpected ways?A)Although Easton and Miss Fairchildhave not seen each other in years,they immediately converse like oldfriendsB)Easton deceives Miss Fairchildduring the story and does not feelguilty about it.C)Easton takes advantage of themarshal's good nature by letting themarshal protect him.D)Although Easton is still charming, hehas adopted a way of life that wouldshock Mise airchild if she knew Express your answer to three significant figures.This balanced equation shows the reaction of sodium hydroxide and sulfuric acid:2NaOH + H2SO4 - Na2SO4 + 2H20.In a laboratory experiment, a student mixes 355 grams of sulfuric acid with an excess of sodium hydroxide. What is the theoretical mass ofsodium sulfate produced? Refer to the periodic table and the polyatomic ion resource.The theoretical mass of sodium sulfate isgrams. Which literary device has Edmund Spenser used in these line from sonnet 9 Please complete the attached proof. Thanks. Jim and Jane purchased their house a year ago and have been transferred out of town. They paid $275,000 for the property and ended up after expenses with only $225,000. Their percentage of loss on the sale was: Phone company A conducted a study that showed 97% customer satisfaction, with a standard deviation of 1%. The sample included 25 people who appear in one of their commercials during the past three years phone company B conducted a study to show 94% customer satisfaction with a standard deviation of 4% a random sample consisting of 100 customers which of the company claims is more believable and why? A.Phone Company A because the time span was longerB. Phone company B bc the sample was not biasedC. Company A bc the standard deviation is smallerD.Company B because the standard deviation is larger The functions f(x) and g(x) are shown on the graph.Ax) = 1xWhat is g(x)?10f(x) = x1g(x) = ?1010-5A. g(x) = [x - 51O B. g(x):= [X1 - 5O.C. g(x) = 1x1 + 5D. g(x) = (x + 51 Amherst Metal Works produces two types of metal lamps. Amherst manufactures 20,000 basic lamps and 5,000 designer lamps. Its simple costing system uses a single Indirect-cost pool and allocates costs to the two lamps on the basis of cirect manufacturing labor-hours. It provldes the following budgeted cost Information: Calculate the total budgeted costs of the basic and designer lamps using Amherst's simple costing system. Begin by Calculating the budgeted indirect cost rate for the single indirect cost pool. First select the formula, then enter the applicable amounts and calculate the rate Abbreviations used: MOH = Manufacturing Overhead Budgeted indirect manufacturing costs Budgeted manufacturing labor hours- Budgeted MOH rate per manutacturing labor-hour 234,000 13,000 S 18 Now calculate the total budgeted costs and per unit costs of the basic and designer lamps using Amherst's simple costing system. (Round all per unit amounts to two decimal places.] Basic lamps Total Per unit Direct materials Direct manufacturing labor Total direct costs Indirect costs allocated Total costs 180,000 $ 200,000 380,000 9.00 10.00 19.00 A substance in a solid phase (state) of matter has what? Vicente has a prism- like water tank whose base area is 1.2 square meters. He bought 6 goldfish at the store and the store owner told him to make sure their density in the tank isnt more than 4 fish per cubic meter. What is the lowest possible height so the fish arent too crowded To examine the effect of high-dose green tea extract on weight loss, researchers conducted a randomized, double-blind trial on a random sample of 115 women with obesity from Taiwan. Some of these women were randomly assigned to the main treatment group taking a high-dose green tea extract ("EGCG") daily for 12 weeks. The published abstract of this 2015 study reports that, "Significant weight loss, from 76.8 11.3 kg to 75.7 11.5 kg (p = 0.025), was observed in the treatment group after 12 weeks of high-dose EGCG treatment."Which of the following inference procedures would be used to reach the quoted conclusion? a. Z procedure for a proportion b. Chi-square for two-way tables c. Chi-square for goodness of fit d. Two sample t procedure for two means e. One sample or matched-pairs t procedure for a mean f. ANOVA for several means Can someone please explain the math on this one to me? Thanks!Assume that is takes an average of 3 man-hours to stack 1 ton of a particular item. In order to stack 36 tons in 6 hours, the number of people required is _____ How did mass production affect consumers?O As factories became more efficient, they hired fewer workers, making jobs scarce.O The prices of mass produced goods decreased, making many items more affordable.O Assembly lines reduced the variety of goods produced, so consumers had fewer choices.O Mass-produced goods tended to have more defects, leaving consumers with worthless products. .What common goal was shared by the United States and European nations during the Age of Imperialism?A. the industrialization of less-developed nationsB. less dependence on foreign tradeC. the independence of underdeveloped countriesD. maintaining the culture and traditions of colonies A sample of carbon dioxide gas (CO2) contains 6 x 1022 molecules. How many moles of carbon dioxide does this represent? This document required nine states to support a bill before it became a law: A) Articles of Confederation B) Mayflower compact C) English bills of right D) Magna Carta On a road trip you see a sign "350 km to Indianapolis". About how many hours will ittake you to drive to Indianapolis if you are traveling at 68 mi/h (1 mile 1.61 km).Round your answer to the nearest hundredth. Juggernaut Satellite Corporation earned $19.6 million for the fiscal year ending yesterday. The firm also paid out 30 percent of its earnings as dividends yesterday. The firm will continue to pay out 30 percent of its earnings as annual, end-of-year dividends. The remaining 70 percent of earnings is retained by the company for use in projects. The company has 2.8 million shares of common stock outstanding. The current stock price is $84. The historical return on equity (ROE) of 14 percent is expected to continue in the future.What is the required rate of return on the stock? Vertical angles are always adjacent.True False