×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• 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.

# Currency in a cost calculation program.

 Forum Search FAQs Links MVPs

## Currency in a cost calculation program.

(OP)
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

### RE: Currency in a cost calculation program.

(OP)
#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;
}

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

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

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!