Reference no: EM132154804
Use C language
Write a program that reads in a series of lines of input character by character (using getchar()). The first line of the input contains an integer which specifies the number of remaining lines of input, each of which contains a floating point number.
The integer value on the first line can be read with scanf(), but all of the following lines can only be read with getchar().
Each line after the first contains a single floating point value, with up to three digits before the decimal point, and up to three digits following the decimal point (but there is not necessarily a decimal point in each number; i.e., it may appear to be an integer, but the digits should be read by your program, and the number should be converted to a corresponding floating point number).
For instance, suppose the following input:
5
3.125
20.25
0.875
921.50
31
The required output is:
Each of the input floating point values, printed on a separate line with three digits of precision, using printf();
On the last line of the output, the string "Total:" followed by the sum of the input values, printed with printf() to 3 digits of precision. For example, the total of the sample input given above is 976.750, so the required output for this input would be:
3.125
20.250
0.875
921.500
31.000
Total: 976.750
Do not concern yourself with small differences in the total due to rounding, as the grader will not deduct points for this.
Be sure to include a descriptive message for the user to input the values correctly. You can assume that the user will follow your directions (which should be consistent with the description above), so no exception handling for incorrect input is required. You cannot change the input specifications given above, however.
CONSTRAINTS:
You are not allowed to use arrays on this portion of the lab assignment.
You must use getchar() to read in the floating point values one character at a time (i.e. DO NOT USE scanf()).
-Only use printf() to output the floating point numbers and the total (Do not useputchar()).
Be sure your directions to the user are clear so they are sure to enter the input data correctly.