I noticed couple of errors you have with your code, on line 36 you send the circumference and the radius to the ComputeCircumference() method even though the function only takes one argument. Another thing, on line 37, you send the area and the radius to the ComputeArea() method in the wrong order according to the function's definition. I also noticed in your ComputeCircumference() method, you multiply 2 * PI * radius where radius is an uninitialized variable.
Also remember that when you pass a variable to a function, the function takes a copy of that variable and doesn't modify the original variable. So in that case, remember to return the result to reflect the change or pass the variable by reference to directly modify the variable.
#include <iostream>
#include <iomanip>
constdouble PI = 3.14;
void banner();
// accept radius as input and return the area as the result
double area( double radius ) ;
// accept radius as input and return the circumference as the result
double circumference( double radius ) ;
double get_radius(); // return the value entered by the user
bool again(); // return true to run it again
void output( double radius, double area, double circumference );
int main()
{
banner();
do
{
constdouble radius = get_radius() ;
// pass the radius, area (returned by the function) and
// circumference (returned by the function) to output
output( radius, area(radius), circumference(radius) ) ;
}
while( again() ) ;
}
void banner()
{
std::cout << "Welcome to my Circle Game!\n""You can input a radius of a circle,\n""I will compute the area and circumference\n""to the nearest tenth.\n\n" ;
}
double area( double radius ) { return PI * radius * radius ; }
double circumference( double radius ) { return 2 * PI * radius ; }
double get_radius()
{
std::cout << "Please enter your circles radius: " ;
double radius ;
if( std::cin >> radius ) // if the user entered a number
{
if( radius > 0.0 ) return radius ; // valid radius was entered, return it
else std::cout << "please enter a positive value for the radius.\n" ;
}
else // non-numeric input eg. "abcd"
{
std::cout << "please enter a number.\n" ;
std::cin.clear() ; // clear the failed state of the stream
std::cin.ignore( 1000, '\n' ) ; // and throw the bad input away
}
return get_radius() ; // try again
}
bool again()
{
std::cout << "Enter another radius? [y/Y] to go again. Or [n/N] to exit: " ;
char input ;
std::cin >> input;
if( input == 'y' || input == 'Y' ) returntrue ;
elseif( input == 'n' || input == 'N' ) returnfalse ;
std::cout << "invalid input.\n" ;
return again() ; // try again
}
void output( double radius, double area, double circumference )
{
std::cout << "Your results are:\n"
<< "You entered: " << radius << " units for the radius.\n\n"
<< std::fixed << std::setprecision(1) // print to to the nearest tenth.
<< " Area: " << area << " units.\n"
<< "Circumference: " << circumference << " units.\n\n" ;
}