Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Currency in a cost calculation program.

Currency in a cost calculation program.

Currency in a cost calculation program.

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


RE: Currency in a cost calculation program.

What does the code look like that prints out $6?

RE: Currency in a cost calculation program.

#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;

 << "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;

RE: Currency in a cost calculation program.

Look into the fixed and setprecision manipulators in <iomanip>.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close