Need help setting precision

I need to set the precision to show 2 decimal places, 1 decimal place, and also a whole number. I wrote it in the code but for some reason it only shows up as a whole number. Why is this? How can I fix it?

Also how can I make the output left justified?

Help would be appreciated, thank you in advance.

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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// This program uses a switch statement to determine
// the item selected from a menu.
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

int main ()

{
int choice;               // To hold menu choice
double area;              // To hold area
int volume;               // To hold volume
double radius;            // To hold radius
double base;              // To hold base
double height;            // To hold height
double sidelength;        // To hold side length
          
// Constants for menu choices
const int CIRCLE_CHOICE = 1,
          TRIANGLE_CHOICE = 2,
          CUBE_CHOICE = 3,
          QUIT_CHOICE = 4;

// Display the menu and get a choice.
cout << "\t\tWhich would you like to calculate?\n\n"
     << "1. Area of a circle\n"
     << "2. Area of a triangle\n"
     << "3. Volume of a cube\n\n"
     << "4. Quit\n\n"
     << "Enter your choice: ";
cin  >> choice;

// Set the numeric output formatting.
cout << fixed << showpoint << setprecision(2);
cout << fixed << showpoint << setprecision(1);
cout << fixed << showpoint << setprecision(0);

// Respond to the user's menu selection.
switch (choice)
{
case CIRCLE_CHOICE:
     cout << "What is the radius? ";
     cin >> radius;
     area = 3.1416 * radius * radius;
     cout << "The result is " << area << endl;
     break;

case TRIANGLE_CHOICE:
     cout << "What is the base? ";
     cin >> base;
     cout << "What is the height? ";
     cin >> height;
     area = 0.5 * base * height;
     cout << "The result is " << area << endl;
     break;
     
case CUBE_CHOICE:
     cout << "What are the side lengths? ";
     cin >> sidelength;
     volume = sidelength * sidelength * sidelength;
     cout << "The result is " << volume << endl;
     break;

case QUIT_CHOICE:
     cout << "Program ending.\n";
     break;
     
     default:
     cout << "The valid choices are 1 through 4. Run the \n"
          << "program again and select one of those.\n";
}
system ("PAUSE");
	return 0;
}
Topic archived. No new replies allowed.