Write program to input a list of names and account balances

Assignment Help C/C++ Programming
Reference no: EM132225804

Programming Assignment -

Where c is a character variable, the scanf( ) function scanf("%c",&c1) will read in one character from the keyboard. If the user hits the <Q> key (for lowercase 'q') followed by the <Enter> key, that action constitutes two characters from the keyboard: 'q' and '\n'. The <Enter> 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",&c1);

scanf("%c",&c2);

then c1 will contain the character from the keyboard, and c2 will contain '\n' generated by the <Enter> key.

If you have a program that contains:

printf("Please enter two characters from the keyboard\n");

scanf("%c",&c1);

scanf("%c",&c2);

then c1 will contain the character from the keyboard, and c2 will contain the 2nd character. The '\n' generated by the <Enter> key will be waiting in a queue to be read by the next scanf("%c", ) in your program.

If you have a program that contains:

printf("Please enter two characters from the keyboard.\n");

scanf("%c",&c1);

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 <Enter> key.

The same holds when reading a number from the keyboard. Hitting the <Enter> 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.\n");

scanf("%d",&i1);

printf("Please enter a character.\n");

scanf("%c",&c1);

Variable i1 will contain the integer, but character variable c1 will always contain the '\n' from the <Enter> key following the integer.

So, if you have a program that contains:

printf("Please enter an integer.\n");

scanf("%d",&i1);

scanf("%c",&c1);

printf("Please enter a character.\n");

scanf("%c",&c2);

Variable i1 will contain the integer, character variable c1 will contain the '\n' from the <Enter> key, character variable c2 will contain the character entered by the user, and the 2nd '\n' from the 2nd <Enteer> key will be waiting in the keyboard queue to be read by the next scanf( ) in your program.

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) Ask the user if they want to enter another name and account balance. Have the user respond with either 'y' or 'n'.

(3) If the user responds with 'n', close the file and end the program.

(4) If the user responds with 'y', instruct the user to enter the last name and hit the <Enter> key. Read this last name and write it to the output file followed by a comma and a blank space.

Then instruct the user to enter the first name followed by the <Enter> key. Read this first name and write it to the output file on the same line followed by a comma and a blank space.

Then instruct the user to enter the account balance as a floating point number followed by the <Enter> key.

Read this value and write it to the same line, but preceded by the dollar sign '$' and printed with exactly 2 digits past the decimal point.

(5) Go to (2) and repeat till the user is done entering the list of names and account balances.

For example, your file out.txt will look like

Doe, Jane, $211.33

Smith, John, $17.44

de Mills, Cecil, $557.44

Reference no: EM132225804

Questions Cloud

Strategy for coping with a threatening environment : Is changing the organization's domain a feasible strategy for coping with a threatening environment?
Design your own text-based adventure game : CSC72003 - Programming - southern cross university - Identify each class and method that you would have to change in order to allow for this type of exit
Construct a plan that ensures a virtual team : Your new team for Health Care, Inc may consist of team members from different locations. Construct a plan that ensures a virtual team's performance
Linear program will have how many constraints : If a transportation problem has 4 origins and 5 destinations, the linear program will have how many constraints?
Write program to input a list of names and account balances : Write a program to input a list of names and account balances from the keyboard and write them into a file called "out.txt"
Provide a brief background of the team and leader : Provide a brief background of the team and leader you are evaluating. What actions, behaviors, characteristics make this team successful?
Find the inverse demand curve : Please provide an answer for the following The demand curve for product X is given by QXd = 300 - 2PX. a. Find the inverse demand curve.
Why do you think the given regulations are important : Locate a current news article discussing a company violating provisions for health insurance instituted by Saudi Arabia's Council of Cooperative Health.
Good example of any of the concepts : For your first post in the first week of this module, try to find a good example of a recent TV series or movie that you watched that you thought was a good

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Create program that uses functions and reference parameters

Create program that uses functions and reference parameters, and asks user for the outside temperature.

  Write a program using vectors and iterators

Write a program using vectors and iterators that allows a user to maintain a personal list of DVD titles

  Write the code required to analyse and display the data

Calculate and store the average for each row and column. Determine and store the values for the Average Map.

  Write a webservices application

Write a webservices application that does a simple four function calculator

  Iimplement a client-server of the game

Iimplement a client-server version of the rock-paper-scissors-lizard-Spock game.

  Model-view-controller

Explain Model-View-Controller paradigm

  Design a nested program

How many levels of nesting are there in this design?

  Convert celsius temperatures to fahrenheit temperatures

Write a C++ program that converts Celsius Temperatures to Fahrenheit Temperatures.

  Evaluate and output the value in the given base

Write C program that will input two values from the user that are a Value and a Base with which you will evaluate and output the Value in the given Base.

  Design a base class shape with virtual functions

Design a base class shape with virtual functions

  Implementation of classes

Implementation of classes Chart and BarChart. Class barChart chould display a simple textual representation of the data

  Technical paper: memory management

Technical Paper: Memory Management, The intent of this paper is to provide you with an in depth knowledge of how memory is used in executing, your programs and its critical support for applications.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd