Code is found below. The sums that I am getting incorrect should add up to the following:
You can mow 198 sq. ft. per min
Time to mow the lawn is 37.8788 minutes.
#include <iostream>
using namespace std;
// Constants for conversion
const double FEET_PER_MILE = 5280;
const double INCHES_PER_FOOT = 12;
const double MINUTES_PER_HOUR = 60;
// Function to convert miles per hour to feet per minute
double mph_to_fpm(double speed) {
return speed * FEET_PER_MILE / MINUTES_PER_HOUR;
}
// Function to calculate area in square feet
double calculate_area(double length, double width) {
return length * width;
}
// Function to calculate time in minutes to mow the lawn
double calculate_time(double area_to_mow, double mow_rate) {
return area_to_mow / mow_rate;
}
int main() {
double length_lawn, width_lawn, length_house, width_house, walking_speed;
// Prompt user for input
cout << "Mowing the lawn by Antionette Calles\n\n";
cout << "Enter five numbers separated by blanks\n";
cout << "They represent the length and width of lawn in feet,\n";
cout << "the length and width of the house in feet,\n";
cout << "and the walking speed in mph\n";
cin >> length_lawn >> width_lawn >> length_house >> width_house >> walking_speed;
// Echo input
cout << "\nThe lawn is " << length_lawn << " by " << width_lawn << " feet" << endl;
cout << "The house is " << length_house << " by " << width_house << " feet" << endl;
cout << "Your walking speed is " << walking_speed << " mph" << endl;
// Calculate areas
double area_lawn = calculate_area(length_lawn, width_lawn);
double area_house = calculate_area(length_house, width_house);
double area_to_mow = area_lawn - area_house;
// Print area to mow
cout << "\nThe area to mow is " << area_to_mow << " square feet" << endl;
// Calculate mow rate
double mow_rate = mph_to_fpm(walking_speed) * (width_lawn / INCHES_PER_FOOT);
// Print mow rate
cout << "You can mow " << mow_rate << " sq. ft. per min" << endl;
// Calculate time to mow
double time_to_mow = calculate_time(area_to_mow, mow_rate);
// Print time to mow
cout << "Time to mow the lawn is " << time_to_mow << " minutes" << endl;
return 0;
}