So I need to place what the user inputs in a table format but I not sure how to. I need some advice or help to figure out this mind block.
This is the question.
Data is available on items sold by a company. The data consists of a 4-digit item number, the
unit price, the price-break quantity and the quantity sold.
The price-break quantity is the smallest quantity that must be bought before a discount or
reduction in price is given. For example, if the price-break quantity is 10, a discount can be
applied if the quantity sold is greater than or equal to 10.
The amount to be paid is normally calculated by multiplying the unit price by the quantity sold.
However, the following applies:
• If the quantity sold is greater than or equal to the price-break quantity, then a 10% discount is
given for that item.
• If a discount is given, and the new amount to be paid exceeds $1000.00, then a further 5%
discount is given.
• If a discount is not given, and the amount to be paid exceeds $1000.00, then a 5% discount is
given.
The following is an example of a line of input data: 1325 23.0 45 40
This indicates that item 1325 costs $23.00 each with a price-break quantity of 45. The quantity
sold was 40.
Write a program, Items.cpp, to do the following:
• Request from the user the number of items to be processed.
• For each item, request from the user the item number, the unit price, the price-break quantity
and the quantity sold.
• Print a suitable heading and under it, for each item, list the item number, unit price, pricebreak
quantity, quantity sold, amount normally paid, discount amount (0.00, if none) and net
payment.
• After all the items have been processed:
o Print the number of valid items in the data
o Print the number of invalid items in the data.
o Print the total amount normally due, the total discount given and the total net payment.
o Print the item number and the net payment of the item with the highest net payment.
Ignore the possibility of a tie.
Note:
• Values entered by the user for the item number and the number of items must be validated.
• To perform the validation for the number of items, your program must ensure that the item
number has the following properties:
o Each item number is a 4-digit number.
o Item numbers begin at 1000.
• To perform the validation for the number of items to be processed:
o Consider the range of numbers that are valid item numbers and use this.
o If the number of items to be processed is larger than this amount the user should be
informed and asked to reenter the amount of numbers to be processed.
• Only items with valid item numbers are processed.
• If an item number is invalid, the item number and an appropriate message are displayed.
Here is my code. Feel free to correct.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
#include <iostream>
using namespace std;
int main(){
int count;
int items;
int i=0;
int item_num;
double unit_price;
double price_break;
double quantity_sold;
double amount_paid;
double discount=0.00;
double discount1=0.00;
double net_payment;
double new_amount;
cout<<"Number of items to be processed: ";
cin>>items;
while (items>15){
cout<<"Number of items to be processed are too large. Re-enter a smaller number(less than 15): "<<endl;
cout<<"Enter the numbers of items to be processed: ";
cin>>items;
}
while(i<items){
i=i+1;
cout<<"4 digit Item Number: ";
cin>>item_num;
while((item_num<1000)||(item_num>5150)){
cout<<"The item number "<<item_num<<" is invalid. Please enter a vaild item number(1000-5150): "<<endl;
cout<<"Enter a 4 digit Item number: ";
cin>>item_num;
}
cout<<"Unit Price: ";
cin>>unit_price;
cout<<"Price break quantity: ";
cin>>price_break;
cout<<"Quantity sold: ";
cin>>quantity_sold;
}
amount_paid=unit_price*quantity_sold;
if(quantity_sold>=price_break){
discount=0.1*amount_paid;
net_payment=amount_paid-discount;//Quantity sold is more than price break which places discount at 10%
}else{
if((quantity_sold>=price_break)&&(new_amount>1000)){//Need help with this. How do I further add 5%?
discount=0.1*amount_paid;
new_amount=amount_paid-discount;
discount1=0.05*new_amount;
net_payment=new_amount-discount1;
}
else{
if(amount_paid>1000){
discount=0.05*amount_paid;
net_payment=amount_paid-discount;}// discount is 5% since the amount to be paid exceeds $1000
else{
if(quantity_sold<price_break){
net_payment=amount_paid;//No discount and the amount to be paid doesn't exceeds $1000
}
}
}
}
cout<<"_______________________________________________________________________________________________________"<<endl;
cout<<"Item Number\tUnit Price\tPrice-break quantity\tQuantity sold\tAmount Paid\tDiscount Amount\tNet Payment";
}
|