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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
|
//Skyler Lopez-Maldonado
//CSCI1010
//Menu functions
//september 20 2013
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
// Function declarations, variables are passed by reference
void mostPowerful(double &, double &, double &, double &, int &);
void discountResults(double &, double &, double &, double &);
void howMany(double &, double &, int &, double &);
char menu(char);
int main() {
double power1; // Power measurement 1
double power2; // Power measurement 2
double power3; // Power measurement 3
double max = 0; // Maximum power measurement, initialized to zero
int num = 0; // Number representing which jetpack is the most powerful
double price; // Price variable
double discount; // Discount percentage
double discountAmount = 0; // Amount taken off as discount
double discountPrice = 0; // Final discounted price
double money; // Amount of money available
double cost; // Cost of item
int numAvail = 0; // Number of items that can be purchased
double moneyLeft = 0; // Money leftover from purchase
char choice = 'n';
char m = 'n',d = 'n',h = 'n',q = 'n';
// Each of these sections that ask for user input should be integrated into
// the menu function. A prototype for the menu function is provided above,
// but the function itself is nearly complete.
cout << "Welcome to Skyler Lopez's Space Travel Company" << endl;
cout << "(M)ost powerful Calculations'" << endl;
cout << "(D)isount calculations" << endl;
cout << "(H)ow many calculations" << endl;
cout << "(Q)uit" << endl;
cout << endl;
cout << "Please enter the option (M, D, H, or Q)";
cout << menu(choice); //needs to be initialized!!! doesn't want to work!
if (choice = m)
{
cout << "Please enter 3 power output measurements in MW: "<< endl;
cin >> power1;
cin >> power2;
cin >> power3;
mostPowerful(power1, power2, power3, max, num);
cout << "The largest power output is " << max << " and is Jetpack number is "
<< num << endl << endl;
}
else if (choice = d)
{
cout << "Please enter a price and a discount amount: ";
cin >> price;
cin >> discount;
discountResults(price, discount, discountAmount, discountPrice);
cout << "The discount amount is " << discountAmount
<< " and the discounted price is " << discountPrice << endl << endl;
}
else if (choice = h)
{
cout << "Please enter amount available and cost of each: ";
cin >> money;
cin >> cost;
howMany(money, cost, numAvail, moneyLeft);
cout << "You can buy " << numAvail << " and have "
<< moneyLeft << " left over." << endl << endl;
cin.get();
cin.get();
system ("PAUSE");
return 0;
}while (choice != q);
}
void mostPowerful(double &p1, double &p2, double &p3, double &max, int &num) {
// Comparison to determine the maximum power output and to set it to
// the max variable as well as setting the num variable based on the max
if ((p1 > p2) && (p1 > p3)) {
max = p1;
num = 1;
}
else if ((p2 > p1) && (p2 > p3)) {
max = p2;
num = 2;
}
else {
max = p3;
num = 3;
}
}
void discountResults(double &p, double &d, double &da, double &dp) {
// Discount amount equlas price times discount
da = p * d;
// Discount price equals price minus discount amount
dp = p - da;
}
void howMany(double &m, double &c, int &na, double &ml) {
// temp is a variable to hold the value of money divided by cost
double temp;
temp = m / c;
// The value stored in temp is cast to an integer to determine the
// number available to purchase
na = (int)temp;
// Money left is determined by subtracting the cost times number available
// to purchase from the amount of money available
ml = m - na * c;
}
char menu(char choice)
{
char decision;
decision = choice;
return decision;
}
|