Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

help me please Using what you have learned above, write a program to input a list of names and account balances from the keyboard and

image text in transcribedimage text in transcribed

help me please

Using what you have learned above, write a program to input a list of names and account balances from the keyboard and write them into a file called "out.txt". (1) Open an output file called "out.txt" for writing. The file "out.txt" will be located in the same directory from which the executable from your program will be run. (2) Write a loop wherein you ask the user if they want to enter another complete name (lastname , firstname) and account balance. Have the user respond with a single character 'y' or 'n' (note: the user will have to hit the key after the single character y' or 'n'). (3) Each time the user responds with 'y', instruct the user to enter the complete name and hit the key. Read this complete name and write it to the output file followed by a semi-colon and a blank space. To read-in the complete name from the keyboard, use another loop that reads a single character at a time from the keyboard and writes a single character to the file. When the character that you read rom the keyboard input is exactly the newline character ' ' (from the key), then you know the user has finished entering the complete name. Next instruct the user to enter the account balance as a floating point number followed by the key. Read this value and write it to the same line, but precede the value by the dollar sign '$' and print the value with exactly 2 digits past the decimal point. Since the user might want to enter another name and account balance, don't leave the ' ' from the key sitting in the keyboard queue, or else that is the 1st character that your next scanf("%c"...) will read in. (4) If at any iteration through the loop, the user responds with 'n' to the question of inputting another name and account balance, close the output file and end the program. For example, your file out.txt will look like Doe, Jane: $211.33 Smith, John: $17.44 de Mills, Cecil: $557.44 ECE 3331. Spring 2020 due Sunday 02/02 at 11:59 pm Programming assignment 02 Turn in this program to the blackboard course website by the due date. Where is a character variable, the scanf(function scanf("%c".&cl) will read in one character from the keyboard. If the user hits the q-key (for lowercase 'q') followed by the key generates the "n' character. Another important fact, is that characters entered from the keyboard that are not yet read by a scanf( will sit in a keyboard queue waiting to be read by the next scanf() in your program. For example: If you have a program that contains: printf("Please enter a single character from the keyboard n"); scanf("%c",&cl); scanf("%c",&c2); and the user presses any letter key followed by the key, then cl will contain the character from the keyboard, and c2 will contain 'n' generated by the key. If you have a program that contains: printf("Please enter two characters from the keyboard n"); scanf("%c",&cl); scanf("%c",&c2); and the user presses any two letter keys followed by the key, then cl will contain the 1" character from the keyboard, and e2 will contain the 2nd character. The 'n' generated by the key will remain waiting in the keyboard queue to be read by the next scanf("%c",), if there is one, in your program. If you have a program that contains: printf("Please enter two characters from the keyboard. In"); scanf("%c",&cl); scanf("%c",&c2); printf("Please enter two more characters from the keyboard n"); scanf("%c",&c3); scanf("%c",&c4); then c3 will contain the 'n' from the first key. The same holds when reading a number from the keyboard. Hitting the key to enter the number generates a 'n' character that is not part of the number that is read from the keyboard. If you have a program that contains: printf("Please enter an integer. In"); scanf("%d",&il); printf("Please enter a character. In"); scanf("%c",&cl); Variable il will contain the integer, but character variable cl will always contain the 'n' from the key, character variable c2 will contain the character entered by the user, and the 2nd 'n' from the 2nd key will be waiting in the keyboard queue to be read by the next scanf() in your program. When you scanf("%d",&il) an integer il from the keyboard, the scanf( ) will skip past any white space (blank space, tabs, newlines from ) that are sitting in the keyboard queue in front of an integer. So, if you have a program that contains: printf("Please Enter an integer. In"); scanf("%d",&il); printf("Please Enter another integer. ")

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

Expert Oracle9i Database Administration

Authors: Sam R. Alapati

1st Edition

1590590228, 978-1590590225

More Books

Students also viewed these Databases questions

Question

Show the properties and structure of allotropes of carbon.

Answered: 1 week ago