hi i'm new to C++ how to make setprecision work for how numbers
Write your question here.
how to make fixed and setprecision show for all my numbers
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
|
{
const double PRIX_FIXE = 50,
SALES_TAX_RATE = .0825,
TIP_PERCENTAGE = .15;
double meals_ordered = 0;
int total_meals,
tax,
tips,
total_due;
cout << "Enter the number of Prix Fixe Meals:" ;
cin >> meals_ordered;
cout << "\n";
cout << "Author's Shawn,King\n"
<< "C.S.1428. 3\n"
<<"Due Date 09/18/13\n\n";
total_meals = PRIX_FIXE * meals_ordered;
tax = total_meals * SALES_TAX_RATE;
tips = (total_meals + tax) * TIP_PERCENTAGE;
total_due = total_meals + tax + tips;
cout << fixed
<< setprecision(2);
cout <<"Prix Fixe Price: $ "
<< setw(9) << PRIX_FIXE
<<"\n";
cout << setw(23)<< "x "
<< setw(9) << meals_ordered
<<"\n\n";
cout <<"Total for # of meals: "
<< setw(4) << total_meals
<<"\n";
cout <<"Sales Taxs @8.25% "
<< setw(7) << tax
<<"\n";
cout << "15% Tips: "
<< setw(16) << tips
<<"\n"
<<"Total Due: $ "
<< setw(7) << total_due;
return 0;
}
|
Last edited on
> how to make fixed and setprecision show for all my numbers
std::fixed
and
std::setprecision()
specify formatting for floating point numbers.
Make the following change:
1 2 3 4 5 6
|
/* double */ int meals_ordered = 0;
/* int */ double total_meals,
tax,
tips,
total_due;
|
thanks that worked
Topic archived. No new replies allowed.