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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
//Brandon Butts
#include <iostream>
#include <iomanip>
using namespace std;
//function prototypes
void bestbuy (double p1, double p2, double p3, double & lowest, int & number);
void discountresults (double price, double discpercent, double & discountprice, double & discountamount); //
void howmany (double monavail, double cost, double & remaining, int & number);
char menu ();
int main()
{
int number = 0;
double price1, price2, price3, lowest = 0, origprice, discountpercent, discountprice = 0, discountamount = 0;
char option;
do
{option = menu();
if (option = 'B')
{
cout << "Best Buy Calculator" << endl;
cout << "Enter the first price." << endl;
cin >> price1;
cout << "Enter the second price." << endl;
cin >> price2;
cout << "Enter the third price." << endl;
cin >> price3;
cout << " " << endl;
bestbuy (price1, price2, price3, lowest, number);
cout << lowest << " is the lowest price." << endl;
cout << number << " is the lowest value." << endl;
system ("pause");
}
else if (option = 'D')
{
cout << "Discount Calculator" << endl;
cout << "Enter the product price." << endl;
cin >> origprice;
cout << "Enter the discount percentage." << endl;
cin >> discountpercent;
cout << " " << endl;
discountresults (origprice, discountpercent, discountprice, discountamount);
cout << "The discount amount is " << discountamount << endl;
cout << "The discount cost is " << discountprice << endl;
system ("pause");
}
}
while (option != 'Q');
system ("pause");
return 0;
}
//inputs three prices, returns the number of the lowest price and what that price is
void bestbuy (double p1, double p2, double p3, double & lowest, int & number)
{
if (p1 < p2 && p3)
{ lowest = p1;
number = 1; }
else if (p2 < p1 && p3)
{ lowest = p2;
number = 2; }
else
{ lowest = p3;
number = 3; }
}
//inputs the price and discount percent, then calculates the discounted price
void discountresults (double price, double discpercent, double & discountprice, double & discountamount)
{
discountamount = price * discpercent;
discountprice = price - discountamount;
}
//inputs the amount of available funds and cost, and outputs how many you can purchase and the leftover funds
void howmany (double monavail, double cost, double & remaining, int & number)
{
number = monavail / cost;
remaining = monavail - cost * number;
}
//provides a menu for the program
char menu ()
{
char option;
cout << " " << endl;
cout << "What would you like to do?" << endl;
cout << "(B)est Buy Calculator" << endl;
cout << "(D)iscoutn Calculator" << endl;
cout << "(H)ow Many? Calculator" << endl;
cout << "(Q)uit" << endl;
cin >> option;
return option;
}
|