Question: Please fix my code! working in Arduino C, so complex functions are NOT ALLOWED! Additional explanations are appreciated but not required. PRINTS THE FOLLOWING When
Please fix my code!
working in Arduino C, so complex functions are NOT ALLOWED!
Additional explanations are appreciated but not required.
PRINTS THE FOLLOWING When user enters 50, 49, 25, 24:
MOWING TIME CALCULATION MOWING TIME CALCULATION Enter yard length: 110010 Enter yard width: 110001 Enter house length: 11001 Enter house width: 11000 At a rate of 0 ft^2/sec it will take 0 min and -1 sec
CODE BELOW
// This tool prompts the user to input a length and width value for property and house // to calculate lawn mowing time. Area1 - Area2 = L1W1 - L2W2 // by integrating a known mowing rate, we can calculate mowing time.
void setup() {
#define MOWRATE 2.00 Serial.begin(115200);
int yard_w; int yard_l; int house_w; int house_l; int lawn; int mn; int sec; int sq_ft_sec; int sq_ft_mn;
Serial.print("MOWING TIME CALCULATION ");
delay(600); Serial.println("Enter yard length: "); // prompt length L1
while(Serial.available()==0); // wait for send
yard_l = Serial.parseFloat(); // return first valid floating point number from monitor (store input)
Serial.println(yard_l,(float)2); // echo print
Serial.print("Enter yard width: "); // prompt width W1
while(Serial.available()==0); // wait for send
yard_w = Serial.parseFloat(); // store input
Serial.println(yard_w,(float)2); // echo print
Serial.print("Enter house length: "); // prompt length L2 while(Serial.available()==0); // wait for send
house_l = Serial.parseFloat(); // return first valid floating point number from monitor (store input)
Serial.println(house_l,2); // echo print
Serial.print("Enter house width: "); // prompt width W2
while(Serial.available()==0); // wait for send
house_w = Serial.parseFloat(); // store input
Serial.println(house_w,2); // echo print
Serial.print("At a rate of "); Serial.print(sq_ft_sec); Serial.print(" ft^2/sec it will take ");
lawn= (yard_l*yard_w) - (house_l*house_w);
mn = (lawn/sq_ft_mn) / 60; sec = (lawn/sq_ft_sec) % 60;
Serial.print(mn); Serial.print(" min and "); Serial.print(sec); Serial.print(" sec");
}
void loop() { // put your main code here, to run repeatedly:
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
