I do not want a negative number input for radius, length, width, base, height. How would I do this. My code is below. It should be pretty self explanatory.
Thanks.
[code=syntax]
#include <iostream>
#include <cmath>
using namespace std;
int main ()
{
double const pi=3.14159;
int radius,
length,
width,
base,
height,
choice;
double area;
//Display the menu and get the user's choice
cout << " Geometry Calculator \n\n";
cout << "1. Calculate the Area of a Circle\n";
cout << "2. Calculate the Area of a Rectangle\n";
cout << "3. Calculate the Area of a Trainge\n";
cout << "4. Quit\n";
cout << "\n";
cout <<"Enter your choice (1-4): ";
cin >> choice;
cout << "\n";
if (choice==1)
{cout << "Please enter the radius of the circle: ";
cin >> radius;
area = radius * pi;
cout << "The area of the circle is: " << area << endl;}
else if (choice==2)
{cout << "Please enter the length of the rectangle: ";
cin >> length;
cout << "Please enter the width of the rectangle: ";
cin >> width;
area = length * width;
cout << "The area of the rectangle is: " << area << endl;}
else if (choice==3)
{cout << "Please enter the base length of the triangle: ";
cin >> base;
cout << "Please enter the height of the triangle: ";
cin >> height;
area = (base * height)/2;
cout << "The area of the triangle is: " << area << endl;}
else if (choice==4)
{cout << "Thanks for trying the Geometry Calculator\n";}
else
{cout << "You can only select options 1-4, run the program again and select a option 1-4\n"; }
return 0;
}