The surface area, s, of a cylinder is given by the formula s = 2πrl where r is the cylinder’s radius and l its length. Using this formula, write a C++ function named surfarea() that accepts the radius and length of a cylinder and returns its surface. Make sure your function is called from main() and correctly returns a value to main(). Have main() use a cout statement to display the value returned.
int main() { double r, l; cout << "Input the radius and length of cylinder." << endl; cin >> r >> l; double s = surfarea(r, l); cout << "The surface area is " << s << "." << endl; system("pause"); return 0; }
Comments
Leave a comment