I need to know how to get the total at the end to have only two decimal places h
ID: 3888030 • Letter: I
Question
I need to know how to get the total at the end to have only two decimal places here is what i have.
cout << "Hello welcome to the Krusty Krab.";
double burgers, shakes, fries;
cout << "Enter the number of Krabby Patties ordered: ";
cin >> burgers;
cout << "Enter the number of Kelp shakes ordered: ";
cin >> shakes;
cout << "Enter the number of fries ordered: ";
cin >> fries;
double BurgersPrice, ShakePrice, FriesPrice;
BurgersPrice = 3.49 * burgers;
ShakePrice = 2.29 * shakes;
FriesPrice = 1.99 * fries;
double Price = BurgersPrice + ShakePrice + FriesPrice;
double Total = Price + Price * 0.02;
cout << "The total is " << Total << " tax included.";
}
Explanation / Answer
Hi
I have modified the code and highlighted the code changes below
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
cout << "Hello welcome to the Krusty Krab.";
double burgers, shakes, fries;
cout << "Enter the number of Krabby Patties ordered: ";
cin >> burgers;
cout << "Enter the number of Kelp shakes ordered: ";
cin >> shakes;
cout << "Enter the number of fries ordered: ";
cin >> fries;
double BurgersPrice, ShakePrice, FriesPrice;
BurgersPrice = 3.49 * burgers;
ShakePrice = 2.29 * shakes;
FriesPrice = 1.99 * fries;
double Price = BurgersPrice + ShakePrice + FriesPrice;
double Total = Price + Price * 0.02;
cout << fixed<<setprecision(2)<<"The total is " << Total << " tax included.";
return 0;
}
Output: