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
|
//Tip Calculator
#include <iostream>
#include <math.h>
using namespace std;
float data[2]; //data[0] = billtotal, 1 = %2tip, 2 = # of peeps
float totalTip;
float totalBill;
float paymentpp;
float calcTotalTip(float a, float b)
{
float r;
r = a * b * .01;
return r;
}
float calcTotalBill(float a, float b)
{
float r;
r = a + b;
return r;
}
float calcPaymentpp (float a, int b)
{
float r;
r = a/b;
return r;
}
void printTotal(float t, float b, float p)
{
cout << "The total amount to tip is $" << t << endl;
cout << "The total bill is $" << b << endl;
cout << "The amount due per person is $" << p << endl;
}
void gatherData(float d[2])
{
cout << "How much was the bill?\n";
cin >> d[0];
if (d[0]<0)
{
cout << "Error! Your bill cannot be less than 0! Please restart the program." << endl;
system("pause");
exit(0);
}
cout << "What percentage do you want to tip?\n";
cin >> d[1];
if (d[1] == 0)
{
cout << "Wow you are a cheap ass mother fucker" << endl;
system("pause");
exit(0);
}
else if (d[1] < 0){
cout << "You must tip a positive amount! Please reset the program!" << endl;
system("pause");
exit(0);
}
cout << "How many people are splitting the check?\n";
cin >> d[2];
if (d[2] < 1)
{
cout << "Error! At least 1 person needs to pay!" << endl;
system("pause");
exit(0);
}
}
int main()
{
float data[2]; //data[0] = billtotal, 1 = %2tip, 2 = # of peeps
float totalTip;
float totalBill;
float paymentpp;
int choice = 1;
gatherData(data);
totalTip = calcTotalTip (data[0], data[1]);
totalBill = calcTotalBill (data[0], totalTip);
paymentpp = calcPaymentpp (totalBill, data[2]);
printTotal(totalTip, totalBill, paymentpp);
system("pause");
return 0;
}
|