#include <iostream>
#include <cstdlib>
#include <cmath>
#include <iomanip>
usingnamespace std;
constdouble pi = 3.141592654;
double circumference(double r);
double area_circle(double r);
double area_sphere(double r);
double volume_sphere(double r);
void print_menu(void);
int main(void)
{
int choice, answer;
double r;
do{
cout << "Enter a radius. \n";
cin >> r;
print_menu();
cin >> choice;
cout << "\n";
switch(choice){
case 1:
cout<<"The circumference of the circle with radius "<< r <<" is "<< circumference(r);
break;
case 2:
cout << "The area of a circle is " << area_circle(r);
break;
case 3:
cout << "The area of a sphere is " << area_sphere(r);
break;
case 4:
cout << "The volume of a sphere is " << volume_sphere(r);
break;
default : cout<<"Invalid option.\n";
}
cout << "Enter y to try again: " ;
cin >> answer;
cin.ignore(80,'\n');
}while(answer == 'y' || answer == 'Y');
system("Pause");
}
void print_menu(void)
{
//prompt the user for the desired equation
cout << "Which would you like to calculate?";
//menu options
cout << "1 The circumference of a circle";
cout << "2 The area of a circle";
cout << "3 The area of a sphere";
cout << "4 The volume of a sphere";
}
[the corresponding functions are here, I know it's not a problem there]
Answer is an int. If you want to hold a character in a variable, you need a char array or string for that. If you want to use single quotes in comparison with a string or char array, you need to do this:
1 2 3 4
if(mystring[integer] == 'character') // Or mychar
{
// Code
}
Replace "integer" with an integer and "character" with a character. Or you could just use a string and double quotes, and you wouldn't need square brackets.
EDIT: Remember that arrays start counting at 0. In case you forgot. So to find the first letter of a string or char array you would do that and replace "integer" with 0.