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?
// This program uses a switch statement to determine
// the item selected from a menu.
#include <iostream>
#include <iomanip>
#include <cmath>
usingnamespace 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
constint 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;
}