Use C language Write a program that reads in a series of lines of input character by...

60.1K

Verified Solution

Question

Programming

Use C language

Write a program that reads in a seriesof lines of input character by character (using getchar()). Thefirst line of the input contains an integer which specifies thenumber of remaining lines of input, each of which contains afloating point number. The integer value on the first line can beread with scanf(), but all of the following lines can only be readwith getchar(). Each line after the first contains a singlefloating point value, with up to three digits before the decimalpoint, and up to three digits following the decimal point (butthere is not necessarily a decimal point in each number; i.e., itmay appear to be an integer, but the digits should be read by yourprogram, and the number should be converted to a correspondingfloating point number). For instance, suppose the followinginput:

5

3.125

20.25

0.875

921.50

31

The required output is:

Each of the input floating point values, printed on a separateline with three digits of precision, using printf();

On the last line of the output, the string “Total:” followed bythe sum of the input values, printed with printf() to 3 digits ofprecision. For example, the total of the sample input given aboveis 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 smalldifferences in the total due to rounding, as the grader will notdeduct points for this.

Be sure to include a descriptivemessage for the user to input the values correctly. You can assumethat the user will follow your directions (which should beconsistent with the description above), so no exception handlingfor incorrect input is required. You cannot change the inputspecifications given above, however.

CONSTRAINTS:

You are not allowed to use arrays on this portion of the labassignment.

You must use getchar() to read in the floating point values onecharacter at a time (i.e. DO NOT USE scanf()).

-Only use printf() to output thefloating point numbers and the total (Do not useputchar()).

Be sure your directions to the user are clear so they are sureto enter the input data correctly.

Answer & Explanation Solved by verified expert
3.9 Ratings (606 Votes)
Complete ProgramSample OutputCODE TO COPY Header files sectioninclude include    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students