really ez c++ help needed

Audiotherapy

Senior member
Apr 21, 2004
471
0
0
my desired output shoud be 185.73, but the program will end up with 187.728. any ideas on why its showing 3 decimal places?



#include <iostream>
using namespace std;

int main()

{


int Length;
int thickness;
int Width;
double cost;

cout <<"What is the length?" << endl;
cin >> Length;

cout <<"What is the thickness?" << endl;
cin >> thickness;

cout <<"What is the width?" << endl;
cin >> Width;

double bfeet = (Length*thickness*Width)/1728.00;

cout <<"What is the cost of the wood per board foot?" << endl;
cin >> cost;

double total = cost * bfeet;

cout <<"The lumber costs:" << total << endl;


return 0;
}
 

screw3d

Diamond Member
Nov 6, 2001
6,906
1
76
Wrong forum buddy.

You need to format you output string to show 2 decimals using precision(2). You need to include another library (iomanip.h) for that.

edit: Corrections. I found out all these by just googling for "c++ formatting output". Repeat after me: Google is your friend.
 

Audiotherapy

Senior member
Apr 21, 2004
471
0
0
length 50
thickness 79
width 25
board foot 3.25

sorry guys, i didnt want to look stupid for asking such a n00b question in programming...