Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- using namespace std;
- double price(char, int);
- double discount(char, double);
- int main()
- {
- char category, stopResult;
- int quantity, counter = 0;
- double totalPrice, afterDisc = 0;
- bool stop = false;
- while(stop == false){
- cout << "Enter the category : ";
- cin >> category;
- cout << "Enter the quantity : ";
- cin >> quantity;
- counter += quantity;
- totalPrice = price(category, quantity);
- afterDisc += discount(category, totalPrice);
- cout << "Do you want to stop and print the receipt (Y/N) : " ;
- cin >> stopResult;
- cout << "\n";
- if (stopResult == 'Y')
- stop = true;
- else
- stop = false;
- }
- cout.setf(ios::fixed);
- cout.precision(2);
- cout << "************** RECEIPT **************" << endl;
- cout << "Quantity Price " << endl;
- cout << "--------- ---------" << endl;
- cout << counter << " RM " << afterDisc << endl;
- cout << "\n\nThank you. Please come again." << endl;
- cout << "*********************************************" << endl;
- return 0;
- }
- double price (char choice, int num){
- double totalPrice = 0;
- if(choice == 'C')
- totalPrice = num * 45.00;
- else if(choice == 'A')
- totalPrice = num * 5.00;
- return totalPrice;
- }
- double discount(char choice, double totalPrice){
- int quantity;
- double priceDisc = 0;
- if(choice == 'C'){
- quantity = totalPrice / 45.00;
- priceDisc = quantity * (45.00 * 0.8);
- } else if(choice == 'A'){
- quantity = totalPrice / 5.00;
- priceDisc = quantity * (5.00 * 0.95);
- }
- return priceDisc;
- }
Add Comment
Please, Sign In to add comment