My Assignment:Today BandN book stores have a deal on eBooks. If you order today you get a discount. The discount is 15% off your total order. Each book costs 8.99. Write a C++ program that will calculate the final cost of your order. The program should be done using functions. Global variables are not allowed. Information should be passed with parameters.
The program will print a set of instructions for the user and give a brief explanation of the purpose. It will ask the user for the number of books you wish to download. It will display the number of books to be downloaded, the subtotal for the books, the discount earned and the total cost for the books.
You should write a user-defined function to perform each of the following tasks:
print the instructions
prompt and read the number of books to be downloaded
calculate the sub total for those books
calculate the discount for your order
calculate the total cost for the downloaded books
print the results in a neat and well labeled form
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
|
#include<iostream>
#include<string>
using namespace std;
void PrintInstructions();
void PrintBill(int numberOfeBooks, float discount, float subTotal);
double SubTotal( float price, float discount);
double CalculateDiscount(int numberOfeBooks, float discount, float price);
int main()
{
while(1)
{
int numberOfeBooks = 0;
float discount = 0.15;
float costPrice = 8.99;
PrintInstructions();
cin>>numberOfeBooks;
system("cls");
float totalDiscount = CalculateDiscount(numberOfeBooks, discount, costPrice);
float subTotal = SubTotal(costPrice, discount);
PrintBill(numberOfeBooks, totalDiscount, subTotal);
}
}
void PrintInstructions()
{
cout<<"Welcome to BandN book store!"<<endl<<"Please enter the number of E-books that you require and hit [ENTER]."<<endl<<"15% discount is being offered and the cost price for each E-book is 8.99"<<endl;
cout<<"Please enter the number of eBooks"<<endl;
}
void PrintBill(int numberOfeBooks, float discountAmount, float subTotal)
{
cout<<"The total amount payable is as following: "<<endl<<endl;
cout<<"----------------------------------"<<endl;
cout<<"No. of E-books: "<<numberOfeBooks<<endl;
cout<<"Total Discount: "<<discountAmount<<endl;
cout<<"Cost/E-book: "<<subTotal<<endl;
cout<<"Amount Payable: "<<numberOfeBooks*subTotal<<endl;
cout<<"----------------------------------"<<endl<<endl;
cout<<"Press [ENTER] to continue"<<endl;
getchar();
system("cls");
}
float SubTotal( float price, float discount)
{
return price-discount;
}
float CalculateDiscount(int numberOfeBooks, float discount, float price)
{
return (numberOfeBooks*price)*discount;
}
|
Why doesn't this project run properly. It loops the first question. Any help?