Problem: Create a program that will calculate the volume and surface area of a cylinder using the radius and height. Your program should contain a main function, a function that will check that the dimension entered is > 0 and a function that will calculate the volume and surface area of the cylinder.
Use this function to check dimension should have two formal parameters, a numeric one for the dimension and a string one that will state if the dimension is for the radius or the height. This function should keep prompting the user to enter the dimension as long the user’s input is less than or equal to 0. This function should return the valid dimension. This function will be called twice from main, once for the radius and once for the height.
#include <iostream>
usingnamespace std;
double dimensions(double, double);
int main ()
{
constdouble PI = 3.14159;
double radius, height;
cout << "Please enter the radius of the cylinder.";
cin >> radius;
double dimensions();
cout << "Please enter the height of the cylinder.";
cin >> height;
double dimensions();
}
double dimensions(double radius, double height)
{
if (radius <=0)
{
cout<< radius <<"is not a vaild entry for the radius!";
cout<< "Please enter a value that is greater than 0 for the radius.";
cin>> radius;
return radius;
}
if (height <= 0)
{
cout<< height <<"is not a vaild entry for the height!";
cout<< "Please enter a value that is greater than 0 for the height.";
cin>> height;
return height;
}
}
But this returns with an error of:
project.cpp(52) : warning C4715: 'dimensions' : not all control paths return a value
The function doesn't do what it's supposed to. Keep trying.
Tip: Its signature should be void dimension(double,constchar *); or something close to that.