I was wondering if there was a way to setw(#) so my couts are aligned AND if I were to change up my wording that they would continue to be aligned. So I guess what I am asking print out the values separate from there indicators, almost like in there own columns??
Example Outputs: (original)
Enter the meal price for the first guest: $45.00
Enter the meal price for the second guest: $50.00
Enter the meal price for the third guest: $100.00
Tax: $13.16
Tip: $41.63
Total Bill: $249.79
Tip Per Person: $13.88
Total Per Person: $83.26
The 3rd guest saved: $16.74
(changing text)
Enter the meal price for the first guest: $45.00
Enter the meal price for the second guest: $50.00
Enter the meal price for the third guest: $100.00
Tax: $13.16
Gratuity: $41.63
Total Bill: $249.79
Tip Per Person: $13.88
Total Per Person: $83.26
The 3rd guest saved: $16.74
(My code)
#include <iomanip> //std:setprecision
#include <iostream>
using namespace std;
int main() {
double ppl1, ppl2, ppl3, meal_total, tax, tip, total, total_bill, per_tip, per_total;
// Get the cost of the meal
cout << "Enter the meal price for the first guest: $";
cin >> ppl1;
// Get the cost of the meal
cout << "Enter the meal price for the second guest: $";
cin >> ppl2;
// Get the cost of the meal
cout << "Enter the meal price for the third guest: $";
cin >> ppl3;
cout << endl;
// Caluates the tax & tip & total
meal_total = ppl1 + ppl2 + ppl3;
tax = meal_total * 6.75 / 100;
tip = (tax + meal_total) * 20 / 100;
total_bill = (tax + meal_total) + tip;
per_tip = tip / 3;
per_total = total_bill / 3;
// I do not have the extra credit in place
cout << "\nTax: $" << setprecision(2) << fixed << tax;
cout << "\nTip: $" << setprecision(2) << fixed << tip;
cout << "\nTotal bill: $" << setprecision(2) << fixed << total_bill;
cout << "\nTip per person: $" << setprecision(2) << fixed << per_tip;
cout << "\nTotal per person: $" << setprecision(2) << fixed << per_total << endl;
// Additional Lab2A adding starts here:
// Adding vars to calulate savings on an per User basis
// then "If" the "Guest total" is greater then 0 we are displaying savings
double ppl1_Tax = ppl1 * 6.75 / 100;
;
double ppl1_Tip = (tax + ppl1) * 20 / 100;
double Price_ppl1 = (ppl1 + ppl1_Tax) + ppl1_Tip;
if ((Price_ppl1 - per_total) > 0) {
cout << "The 1st guest saved: $" << (Price_ppl1 - per_total) << endl;
}
double ppl2_Tax = ppl2 * 6.75 / 100;
;
double ppl2_Tip = (tax + ppl2) * 20 / 100;
double Price_ppl2 = (ppl2 + ppl2_Tax) + ppl2_Tip;
if ((Price_ppl2 - per_total) > 0) {
cout << "The 2nd guest saved: $" << (Price_ppl2 - per_total) << endl;
}
double ppl3_Tax = ppl3 * 6.75 / 100;
;
double ppl3_Tip = (tax + ppl3) * 20 / 100;
double Price_ppl3 = (ppl3 + ppl3_Tax) + ppl3_Tip;
if ((Price_ppl3 - per_total) > 0) {
cout << "The 3rd guest saved: $" << (Price_ppl3 - per_total) << endl;
}
return 0;
}