Help with C++ assignment

D

Diane Ch

I have the following assignment:
For this assignment you are to design and implement a
program that will be used to generate a customer billing
report from item information input by a user.
The input for your program consists of the name of the
customer, which can be up to 25 characters long (no
spaces), followed by data for each of the items ordered
by that customer. The data for an item consists of:
... an item description that can be up to 20
characters long (input),
... the quantity ordered of that item (input), and
... The unit price of that item (input).

Your program should first prompt the user to enter the
name of a customer. Next it should repeatedly ask the
user if there is data pertaining to an item to be input
until the user responds in the negative. Each time the
user responds in the affirmative, the program should
prompt the user to enter the three data values pertaining
to an item. The data entered should be used to generate
the report having the format depicted below. A customer
receives a 10% discount for an item if the quantity
purchased is 10 or more. The item total is computed as
the product of unit price and quantity, minus the
discount amount.

Then I have to print the report in a certain format. I am
having trouble coding the input part of the assignment. I
am trying to use a while loop and it is either not
looping or looping without stopping.

This is what I wrote so far:

#include <iostream>
#include <iomanip>

using namespace std;

char item_description, customer_name, selection;
int quant_ordered;
float unit_price, item_total, discount;
double total_unitprice, total_itemprice, total_dsct;

main()

{
cout<<"This program will produce a customer order
report.\n";
cout<<"Please enter customer's name\n";
cin>>customer_name;

cout<<"Do you have order data to enter? Enter y
for yes and n for no:\n";
cin>>selection;

while (selection=='y') // Prompt user
for order data
{
cout<<"Please enter item description: \n";
cin>>item_description;
cout<<"Please enter quantity ordered: \n";
cin>>quant_ordered;
cout<<"Please enter unit price: \n";
cin>>unit_price;

cout<<"Do you have other items to enter?
Enter y for yes and n for no:\n";
cin>>selection;


}

return 0;

}

What is the problem here????????

..
 
D

David

What is happening is that the variable selection is
getting the newline or carriage return when the user hits
the enter key. Try using getChar() instead. Your code
would be

selection = getChar();


Also you should add some error checking in case the user
puts in anything other than a y or n.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top