• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

really ez c++ help needed

Audiotherapy

Senior member
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;
}
 
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.
 
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...
 
Back
Top