I was finishing up my project, and I am trying to get the decimal point to show as a dollar amount, so two decimals. I used setpercision(2) because I thought that would only affect the amount of digits after the decimal place. However, it is affecting the whole number.
#include <iostream>
#include <iomanip>
usingnamespace std;
double CalculateAmountPerPerson(double TotalBill, double TipPercentage, int NumFriends) //Identifying the functions and what they respresent
{
double totalTipPerPerson = (TotalBill * TipPercentage) / NumFriends;
double totalPerPerson = (TotalBill / NumFriends) + totalTipPerPerson;
return totalPerPerson;
}
double CalculateAmountPerPerson(double TotalBill, double TipPercentage, int NumFriends); /* I am using doubles because I
want to be able to show the full amount w/ cents*/
int main()
{
int friends;
double damage;
double tip;
cout << "So whats the damage...how much do you owe?" << endl;
cin >> damage;
while (damage < 1)
{
cout << " So why do you need me if your meal was free...? Try again" << endl;
cin >> damage;
}
cout << "Ok thats not too bad... well how many friends will pitch in?" << endl;
cin >> friends;
while (friends < 1)
{
cout << " You have no friends.. that so sad... but again why do you need me?" << endl;
cout << "Try again.." << endl;
cin >> friends;
}
for (tip = .10; tip <= .30; tip += .025)
{
cout << "If you are kind enough to leave a " << tip * 100 << "%, each friend pays $";
cout << setprecision(2) << CalculateAmountPerPerson(damage, tip, friends) << ".";
cout << endl;
}
system("PAUSE");
return 0;
}