Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

can anyone help me complete with my code i'm not understanding how to use an ACCUMULATOR and i am also struggling with understanding FOR LOOPS

image text in transcribed

image text in transcribed

image text in transcribed

can anyone help me complete with my code i'm not understanding how to use an ACCUMULATOR and i am also struggling with understanding FOR LOOPS if you can please leave comments to help me better understand how to solve similar problems for the future please don't use arrays. C++ is the language please someone help!

5.6 Lab 31: Sum and Average Write a program that computes the total hours worked and the average hours worked for a user-defined number of employees. Your program should first read in the number of employees and then the number of hours worked for each of those employees. Output the number of hours worked for each employee after the value is read in. The program should accomplish the following objectives: - include self-documenting variable names of type integer, comments, and properly spaced statements, - make use of a FOR loop to read in the hours worked for each employee and output that value, - sum the hours using an accumulator variable, - display the sum outside the loop, - calculate and display the average hours worked outside the loop (display the average with 2 significant digits after the decimal point). Hint: Inside the for loop you will need to read in the hours worked, output the value in the specified format, and add the hours value to an accumulator variable. Don't forget to initialize your accumulator variable to 0 before entering the for loop. For more information and examples, refer to slide 4 of CS1336_Lect5d_more_on_FOR_loop.pptx and Pr5-12.cpp. When the input is as shown in Figure 1, your program should produce output as shown in Figure 2. Figure 1: (sample input) Hint: Inside the for loop you will need to read in the hours worked, output the value in the specified format, and add the hours value to an accumulator variable. Don't forget to initialize your accumulator variable to 0 before entering the for loop. For more information and examples, refer to slide 4 of CS1336_Lect5d_more_on_FOR_loop.pptx and Pr5-12.cpp. When the input is as shown in Figure 1, your program should produce output as shown in Figure 2. Figure 1: (sample input) 3251215 Figure 2: (sample output) Employee 1 worked 25 hours Employee 2 worked 12 hours Employee 3 worked 15 hours The sum of hours worked by 3 employees is 52 The average number of hours worked is 17.33 5.6.1: Lab 31: Sum and Average 10/10

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Transactions On Large Scale Data And Knowledge Centered Systems X Special Issue On Database And Expert Systems Applications Lncs 8220

Authors: Abdelkader Hameurlain ,Josef Kung ,Roland Wagner ,Stephen W. Liddle ,Klaus-Dieter Schewe ,Xiaofang Zhou

2013th Edition

3642412203, 978-3642412202

More Books

Students also viewed these Databases questions