Untitled
unknown
c_cpp
2 years ago
1.8 kB
4
Indexable
Never
#include <iostream> using namespace std; void average(); // function initializing int main(){ int choice; system("clear"); cout << "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n"; cout << "[1] Compute and average 5 integer inputs\n"; cout << "[2] De La Salle Armoury Discount Calculator\n"; cout << "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n"; cout << "Enter your choice: "; cin >> choice; switch(choice){ case 1: average(); // function called break; case 2: double amount, net_amount, discount; cout << "Enter Amount bought in D Armoury: "; cin >> amount; if(amount >= 1 && amount <= 1500){ discount = 0.15 * amount; } else if(amount >= 1501 && amount <= 3500){ discount = 0.20 * amount; } else if(amount >= 3501 && amount <= 5000){ discount = 0.25 * amount; } else if(amount > 5000){ discount = 0.30 * amount; } else {cout << "error";} net_amount = amount - discount; // apply the discount to the total amount paid cout << "Your Discount is : " << discount << " php"<< endl; cout << "TOTAL PRICE : " << net_amount << " php"; break; default: cout << "Invalid Input"; } return 0; } void average(){ int input, ave; int total = 0; for (int i = 0; i < 5; i++){ cout << "Enter an Integer: "; cin >> input; total += input; // equivalent to total = total + input; } ave = total / 5; cout << endl << "The total is: " << total; cout << endl << "The average of your 5 inputs is: " << ave; }