1.
Write the function
rectangleInfo
which prompts the user for the width and height of a rectangle. Then rectangleInfo
prints out the area and perimeter of the rectangle.
Solution.
Below is one way to implement the program. We prompt the user for input using
cin
before printing the area and perimeter.
#include <iostream>
using namespace std;
void rectangleInfo() {
int height, width;
cout << "Please enter the height and width of a rectangle separated by spaces: ";
cin >> height >> width;
cout << "The area of the rectangle is " << height * width << endl;
cout << "The perimeter of the rectangle is " << 2 * (height + width) << endl;
}
int main() {
rectangleInfo();
}