//an example of C++ functions //csci107, Laura Toma #include const float PI = 3.1412; //describes the program to the user void describeProgram() { cout << "This program will ask for a radius and will compute " << "the circumference or the area of a circle with that radius. " << "Then it will repeat.." << endl; return; } //returns the circumference of a circle of radius rad float compute_circum(float rad) { float circum = 2 * PI * rad; return circum; } //returns the area of a circle of radius rad float compute_area(float rad) { float area = PI * rad * rad; return area; } int main() { char answer = 'y', option; float r; //describe the program to the user describeProgram(); while (answer == 'y') { cout << "enter a radius: "; cin >> r; //read option cout <<"what would you like to compute? "; cout << "(press a for area, c for circumference): "; cin >> option; if (option == 'c') { cout << "The circumference is: " << compute_circum(r) << endl; } else if (option == 'a') { cout << "The area is: " << compute_area(r) << endl; } else { cout << "not a valid option..\n"; } //again? cout << "again? (y/n): "; cin >> answer; } }