In: Computer Science
I need my code output values edited to be formatted to two decimal places (i believe using setprecision), i will need you to edit my code toformat each menu option to 2 decimal places: provided is my code
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
double radius;
double base;
double height;
double length;
double width;
double Area;
const double PI = 3.14159;
int choice;
// display menu
cout << "Geometry Calculator" << endl
<< endl;
cout << " 1. Calculate the Area of a Circle"
<< endl;
cout << " 2. Calculate the Area of a Rectangle"
<< endl;
cout << " 3. Calculate the Area of a Triangle"
<< endl;
cout << " 4. Quit" << endl <<
endl;
cout << "Enter your choice (1-4):" <<
endl;
cin >> choice;
//validate and process the menu
switch(choice)
{
case 1:
cout <<
"\n";
cout <<
"Enter the radius of the circle: ";
cin >>
radius;
if (radius
> 0)
{
Area = PI * radius * radius;
cout << "\n";
cout << "Area of Circle is: " <<
Area << setprecision(2) << endl;
}
else
{
cout << "The radius can not be less than
zero. Only enter positive values for your radius.";
}
break;
case 2:
cout <<
"\n";
cout <<
"Enter the length of the rectangle: ";
cin >>
length;
cout <<
"Enter the width of the rectangle: ";
cin >>
width;
if (length
> 0 && width > 0)
{
Area = length * width;
cout << "\n";
cout << "Area of Rectangle is: " <<
Area << endl;
}
else
{
cout << "\nOnly enter positive values for
length and width.";
}
break;
case 3:
cout <<
"\n";
cout <<
"Enter the base of the Triangle: ";
cin >>
base;
cout <<
"Enter the height of the Triangle: ";
cin >>
height;
if (base >
0 && height > 0)
{
Area = 0.5 * base * height;
cout << "\n";
cout << "Area of the Triangle is: "
<< Area << endl;
}
else
{
cout << "\nOnly enter positive values for
base and height.";
}
break;
case 4:
cout <<
"Exiting Geometry Calculator\nGoodbye!\n";
break;
default: cout << "Sorry,
that was an invalid entry!\nPlease re-run the program and "
<< "enter
a valid menu choice.\n";
}
return 0;
}
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
double radius;
double base;
double height;
double length;
double width;
double Area;
const double PI = 3.14159;
double tmp;
int choice;
cout<<fixed<<setprecision(2);
// display menu
cout << "Geometry Calculator" << endl << endl;
cout << " 1.00 Calculate the Area of a Circle" << endl;
cout << " 2.00 Calculate the Area of a Rectangle" << endl;
cout << " 3.00 Calculate the Area of a Triangle" << endl;
cout << " 4.00 Quit" << endl << endl;
cout << "Enter your choice (1.00-4.00):" << endl;
cin >> tmp;
choice = (int)tmp;
//validate and process the menu
switch(choice)
{
case 1:
cout << "\n";
cout << "Enter the radius of the circle: ";
cin >> radius;
if (radius > 0)
{
Area = PI * radius * radius;
cout << "\n";
cout << "Area of Circle is: " << Area << setprecision(2) << endl;
}
else
{
cout << "The radius can not be less than zero. Only enter positive values for your radius.";
}
break;
case 2:
cout << "\n";
cout << "Enter the length of the rectangle: ";
cin >> length;
cout << "Enter the width of the rectangle: ";
cin >> width;
if (length > 0 && width > 0)
{
Area = length * width;
cout << "\n";
cout << "Area of Rectangle is: " << Area << endl;
}
else
{
cout << "\nOnly enter positive values for length and width.";
}
break;
case 3:
cout << "\n";
cout << "Enter the base of the Triangle: ";
cin >> base;
cout << "Enter the height of the Triangle: ";
cin >> height;
if (base > 0 && height > 0)
{
Area = 0.5 * base * height;
cout << "\n";
cout << "Area of the Triangle is: " << Area << endl;
}
else
{
cout << "\nOnly enter positive values for base and height.";
}
break;
case 4:
cout << "Exiting Geometry Calculator\nGoodbye!\n";
break;
default: cout << "Sorry, that was an invalid entry!\nPlease re-run the program and "
<< "enter a valid menu choice.\n";
}
return 0;
}



