Answer:
C++ code explained below
Step-by-step explanation:
CODE
#include <iostream>
using namespace std;
// prototypes go here
void getInput(double *l, double *w) {
cout << "Enter Length: ";
cin >> *l;
if(*l < 0) {
return;
}
cout << "Enter Width: ";
cin >> *w;
while(*w < 0) {
cout << "Width must be positive! Try Again" << endl;
cout << "Enter Width: ";
cin >> *w;
}
}
double calculations(double l, double w, double *perimeter) {
*perimeter = 2 * (l + w);
return l*w;
}
void printResults(double l, double w, double perimeter, double area) {
cout << "Rectangle Dimensions: " << l << " X " << w << endl;
cout << "perimeter: " << perimeter << endl;
cout << "Area: " << area << endl;
return;
}
int main()
{
double t;
// test(&t);
double length;
double width;
double perimeter;
double area;
//below line has to change if you need to work this example
//reason is length and width are local variable to main so other function can only change if address is passed so i have plase & sign before the variables while passing
//same has to be done for perimeter
getInput(&length, &width);
while (length >= 0)
{
area = calculations(length, width, &perimeter);
printResults(length, width, perimeter, area);
getInput(&length, &width);
}
}