Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Currency in a cost calculation program.

Status
Not open for further replies.

ansmwke

Programmer
Jul 8, 2007
5
0
0
US
I am writing a program where it calculates cost of books, movies, and peanuts and figures out shipping. I have all the code done, and my output shows up as $6 instead of $6.00

how can i make it show up as $6.00

thanks
 
What does the code look like that prints out $6?
 
#include <iostream>
#include <string>
using namespace std;

int main()
{


cout << "How many books?";
int book_qty;
cin >> book_qty;

cout << "How many movies?";
int movie_qty;
cin >> movie_qty;

cout << "How many pounds of peanuts?";
int peanut_lb;
cin >> peanut_lb;

double book_cost = book_qty*9.00;
double movie_cost = movie_qty*16.00;
double peanut_cost = peanut_lb*1.80;
double subtotal = book_cost + movie_cost + peanut_cost;

double book_shipping = (1.00*book_qty);
double movie_shipping = (movie_qty * 16.00 * .05);
double peanut_shipping = (peanut_lb*.20);
double shipping = book_shipping + movie_shipping + peanut_shipping;
double total_sale = shipping + subtotal;

cout
<< "Books: \t" << "$"<< book_cost << endl
<< "Movies: \t" << "$"<< movie_cost << endl
<< "Peanuts: \t" << "$"<< peanut_cost << endl
<< "Subtotal: \t" << "$"<< subtotal << endl
<< "Shipping: \t" << "$"<< shipping << endl
<< "Total : \t" << "$"<< total_sale << endl;




return 0;
}
 
Look into the fixed and setprecision manipulators in <iomanip>.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top