Need help with setprecision

//#include "stdafx.h"
#include <iostream>
#include <iomanip>
using namespace std;

int main()
//int _tmain(int argc, _TCHAR* argv[])
{
double l;
double h;
double w;

//input

cout << " what is the length ";
cin >> l;
cout << " what is the height ";
cin >> h;
cout << " what is the width ";
cin >> w;

//output

cout << " the volume is " << setprecision(2) << l * w *h << endl;
cout << " the surface area is " << setprecision(2) << ( 2 * l * h ) + 2 * ( h * w ) + 2 * ( l * w) << endl;



return 0;
}



I need decimal places after my output.
thanks for any help
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <iostream>
#include <iomanip>
#include <conio.h>
using namespace std;
 
int main()
 //int _tmain(int argc, _TCHAR* argv[])
 {
 double l;
 double h;
 double w;

 //input
 
cout << " what is the length: ";
 cin >> l;
 cout << " what is the height: ";
 cin >> h;
 cout << " what is the width: ";
 cin >> w;
 
//output
cout << fixed << setprecision(2);
cout << " the volume is " << l * w *h << endl;
cout << " the surface area is " << ( 2 * l * h ) + 2 * ( h * w ) + 2 * ( l * w) << endl;


getch();
return 0;
 }




im assuming your formulas are correct but this will fix your output issues
Topic archived. No new replies allowed.