Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / October 2003

Tip: Looking for answers? Try searching our database.

Help with C++ assignment

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Diane Ch - 29 Oct 2003 08:35 GMT
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????????

.
David - 30 Oct 2003 14:58 GMT
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.

>-----Original Message-----
>I have the following assignment:
[quoted text clipped - 78 lines]
>
>.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.