Hello all. I am trying to round a float number and then have that number added to a total of numbers. the number i am trying to round up is the one called tax. It will take the last digit and round up by one. I have provided the code for just this occasion. Remember, i am having trouble getting the variable tax to round up one decimal digit. And that value needs to go and then be added to the total cost variable. THANK YOU!
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main (void)
{
//declarations
int guests;
float costPerPerson;
float totalCost;
float tax;
float tip;
float food;
//string caterername;
char caterername [256];
const float SalesTax = .06;
const float Gratuity = .15;
//User will enter name of caterer, cost per person, and number of guests
//values will be stored and retrieved later.
cout << "Please enter a caterer name: ";
//cin >> caterername;
cin.getline (caterername,256); //code structure taken from cplusplus.com
// >> endl;
//cout << caterername;
//>> endl;
cout << "Please enter the cost per person: $";
// << endl;
cin >> costPerPerson;
//<< endl;
//cout << costPerPerson;
cout << "Please enter the number of guests attending: ";
//<< endl;
cin >> guests;
//>> endl;
//cout << guests;
//Values entered by the user will be retrieved and used to calculate
//the meal information
food = costPerPerson * float(guests); //calculates the cost of food only
tax = food * SalesTax; //calculates the cost of the sales tax
tip = food * Gratuity ; //calculates the cost of the tip
totalCost = food + tax + tip; //calculates the total cost of the meal
cout << endl;
cout << endl;
cout << endl;
//Computer will print a reciept for the user containing
//caterer name, cost of food, tax, tip, and total cost.
cout <<" Here is the estimated cost reciept: "
<< setw (6)
<< setprecision (2)
<< showpoint
<< fixed
<< endl;
cout << "Caterer Name: "
<< caterername
<< endl;
cout << "Cost of food: $"
<< food
<< endl;
cout << setw (6)
<< "Tax: $"
<< setprecision(2)
<< tax
<<endl;
cout << "Tip: $"
<< tip
<<endl;
cout << "Total Cost: $"
<< totalCost
<< endl;
return 0;
}
I need them to be rounded up such as the way you would round money. $23.453 = $23.46. I need the last digit in that area to round up to the next highest digit! It is to calculate the tip. So any number greater than 0 will automatically round up.