Question

In: Computer Science

I have a problem with my code. It does not run. Please can someone check the...

I have a problem with my code. It does not run. Please can someone check the code and tell me where I went wrong?

This is the question:

Program Specification: Write a C program that takes the length and width of a rectangular yard, and the length and width of a rectangular house (that must be completely contained in the yard specified) as input values. Assuming that the yard has grass growing every where that the house is not covering, and you own a lawn mower can mow one square foot per second, on average. Compute the time (in minutes) needed to mow the yard.

Requirements: 1. Use conditional logic to display an error message (instead of erroneous output) only if neither the specified house nor the same house rotated 90 degrees does not fit on the specified yard. 2. Otherwise - display all of the user’s inputs and the computed result in a reasonable report like format.

This is the code:

#include <stdio.h>
#include <stdlib.h>

int main()
{
   float Length_y;
   float Width_y;
   float Length_h;
   float Width_h;
   float Area_y;
   float Area_h;
   float Area_G;
   float Time;

   printf("Enter the length of the yard: \n");
   scanf("%f", &Length_y);

   printf("Enter the width of the yard: \n");
   scanf("%f", &Width_y);

   printf("Enter the length of the house: \n");
   scanf("%f", &Length_h);

   printf("Enter the width of the house: \n");
   scanf("%f", &Width_h);

   if ((Length_h>=Length_y)||(Width_h>=Width_y))
   {
       Length_h= Width_h;
       Width_h= Length_h;
       Area_y= Length_y*Width_y;
       Area_h= Length_h*Width_h;
       Area_G= Area_y-Area_h;
       Time= Area_G/60;

       printf("Length of the yard is %f \n", Length_y );
       printf("Width of the yard is %f \n", Width_y );
       printf("Length of the house is %f \n", Length_h );
       printf("Width of the house is %f \n", Width_h);
       printf("Area of the yard is %f \n", Area_y);
       printf("Area of the house is %f \n", Area_h);
       printf("Area with grass is %f \n", Area_G);
       printf("Time to mow lawn is %f \n", Time);
   }
   else
   {
       printf("House does not fit in yard.\n");
   }
   return 0;

}

Solutions

Expert Solution

Error code with comments:

#include <stdio.h>
#include <stdlib.h>

int main()
{
   float Length_y;
   float Width_y;
   float Length_h;
   float Width_h;
   float Area_y;
   float Area_h;
   float Area_G;
   float Time;

   printf("Enter the length of the yard: \n");
   scanf("%f", &Length_y);

   printf("Enter the width of the yard: \n");
   scanf("%f", &Width_y);

   printf("Enter the length of the house: \n");
   scanf("%f", &Length_h);

   printf("Enter the width of the house: \n");
   scanf("%f", &Width_h);

   if ((Length_h>=Length_y)||(Width_h>=Width_y)) // The bodies of if and else are reversed
   {
       Length_h= Width_h; // if a is enterd in length_h and b in width_h then this step makes
       Width_h= Length_h; // width_h= length_h = b. these two steps are not required
       Area_y= Length_y*Width_y;
       Area_h= Length_h*Width_h;
       Area_G= Area_y-Area_h;
       Time= Area_G/60;

       printf("Length of the yard is %f \n", Length_y );
       printf("Width of the yard is %f \n", Width_y );
       printf("Length of the house is %f \n", Length_h );
       printf("Width of the house is %f \n", Width_h);
       printf("Area of the yard is %f \n", Area_y);
       printf("Area of the house is %f \n", Area_h);
       printf("Area with grass is %f \n", Area_G);
       printf("Time to mow lawn is %f \n", Time);
   }
   else
   {
       printf("House does not fit in yard.\n");
   }
   return 0;

}

Corrected Code ------------------------------------------------------------------------------------------

#include <stdio.h>
#include <stdlib.h>

int main()
{
float Length_y;
float Width_y;
float Length_h;
float Width_h;
float Area_y;
float Area_h;
float Area_G;
float Time;

printf("Enter the length of the yard: \n");
scanf("%f", &Length_y);

printf("Enter the width of the yard: \n");
scanf("%f", &Width_y);

printf("Enter the length of the house: \n");
scanf("%f", &Length_h);

printf("Enter the width of the house: \n");
scanf("%f", &Width_h);

if ((Length_h>=Length_y)||(Width_h>=Width_y))
{
printf("House does not fit in yard.\n");
}
else
{
Area_y= Length_y*Width_y;
Area_h= Length_h*Width_h;
Area_G= Area_y-Area_h;
Time= Area_G/60;

printf("Length of the yard is %f \n", Length_y );
printf("Width of the yard is %f \n", Width_y );
printf("Length of the house is %f \n", Length_h );
printf("Width of the house is %f \n", Width_h);
printf("Area of the yard is %f \n", Area_y);
printf("Area of the house is %f \n", Area_h);
printf("Area with grass is %f \n", Area_G);
printf("Time to mow lawn is %f \n", Time);
}
return 0;

}


Related Solutions

Can someone please provide the answers so I can check my work? Baldwin Corporation Excerpts from...
Can someone please provide the answers so I can check my work? Baldwin Corporation Excerpts from the Statement of Financial Position for Baldwin Corporation as of September 30, Year 5, are presented below. Cash $   950,000 Accounts receivable (net) 1,675,000 Inventories   2,806,000 Total current assets $5,431,000 Accounts payable $1,004,000 Accrued liabilities      785,000 Total current liabilities $1,789,000 The Board of directors of Baldwin Corporation met on October 4, Year 5, and declared regular quarterly cash dividends amounting to $750,000 ($0.60 per share)....
In Python I have a code: here's my problem, and below it is my code. Below...
In Python I have a code: here's my problem, and below it is my code. Below that is the error I received. Please assist. Complete the swapCaps() function to change all lowercase letters in string to uppercase letters and all uppercase letters to lowercase letters. Anything else remains the same. Examples: swapCaps( 'Hope you are all enjoying October' ) returns 'hOPE YOU ARE ALL ENJOYING oCTOBER' swapCaps( 'i hope my caps lock does not get stuck on' ) returns 'I...
I have bolded the answers I chose. I just need someone to check my work and...
I have bolded the answers I chose. I just need someone to check my work and if I'm wrong possibly explain why, please? 1. If a stock pays a dividend, the owner of a call option will see the value of their option decrease by the amount of that dividend payment. a. true b. false 2. DEF stock currently trades for $40. Both American calls and puts are available on the stock. All else being constant, which of the following...
can someone finish and check my code on main. cpp? Its not working for me even...
can someone finish and check my code on main. cpp? Its not working for me even though im sure my code make sense is it possible to output each function to show they work. this is supposed to be a vector class library made from allocated memory i have included templated functions in the class file to help create the rest of the functions. Thank you so much note: i did not include main.cpp because it  was empty- im hoping someone...
This is the code I have. My problem is my output includes ", 0" at the...
This is the code I have. My problem is my output includes ", 0" at the end and I want to exclude that. // File: main.cpp /*---------- BEGIN - DO NOT EDIT CODE ----------*/ #include <iostream> #include <fstream> #include <sstream> #include <iomanip> using namespace std; using index_t = int; using num_count_t = int; using isConnected_t = bool; using sum_t = int; const int MAX_SIZE = 100; // Global variable to be used to count the recursive calls. int recursiveCount =...
can someone please check this code? – Enter Quantity of Numbers Design a program that allows...
can someone please check this code? – Enter Quantity of Numbers Design a program that allows a user to enter any quantity of numbers until a negative number is entered. Then display the highest number and the lowest number. For the programming problem, create the pseudocode and enter it below. Enter pseudocode here start     Declarations           num number           num high             num low              housekeeping()     while number >=0 detailLoop()      endwhile      finish() stop housekeeping( )           output...
How would I make it so that when I run my code it does not ask...
How would I make it so that when I run my code it does not ask for input (not having to enter after the statement and enter 0 for example) after ROXY (Forever ROXY Enterprises) appears? Like it would tell me the second statement right away along with the Roxy phrase. This is in C++. My code: #include / #include using std::endl; int main() {    void readAndConvert();    unsigned int stockSymbol;    unsigned int confNum;    std::cout << "ROXY...
Hi I have a java code for my assignment and I have problem with one of...
Hi I have a java code for my assignment and I have problem with one of my methods(slice).the error is Exception in thread "main" java.lang.StackOverflowError Slice method spec: Method Name: slice Return Type: Tuple (with proper generics) Method Parameters: Start (inclusive) and stop (exclusive) indexes. Both of these parameters are "Integer" types (not "int" types). Like "get" above, indexes may be positive or negative. Indexes may be null. Description: Positive indexes work in the normal way Negative indexes are described...
Can you please check for the error in my code?: #data object is created text_data =...
Can you please check for the error in my code?: #data object is created text_data = {"the_final_output": [{"abs": ""}, {"abs": ""}, ..., {"abs": ""}]} #a list is created main_terms = [] #iterating every data in the_final_output for i in range(len(text_data["the_final_output"]): blob = TextBlob(text_data["the_final_output"][i]["abs"]) main_terms.append(blob.polarity)    #sentiment analysis sorts the text into positive, neutral, and negative. tp = sum(main_terms) #if tp is less than 0, it's negative if tp < 0: print("Negative") #if tp is greater than 0, it's positive elif...
I have a problem with the code for my project. I need the two clients to...
I have a problem with the code for my project. I need the two clients to be able to receive the messages but the code I have done only the server receives the messages. I need the clients to be able to communicate with each other directly not throught the server. The requirements of this "local chat" program must meet are: 1. The chat is performed between 2 clients and a server. 2. The server will first start up and...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT