Write a Program That Reads in the Length and the Width of a Rectangular Yard
You should upgrade or use an alternative browser.
- Forums
- Homework Assistance
- Engineering science and Comp Sci Homework Aid
C program to calculate area and a few other things
- Thread starter Arnoldjavs3
- Start date
Homework Argument
Hullo, currently I have this assignment:
Write a program by going through the half dozen problem solving steps that reads in the length and width of a rectangular yard in feet, the length and width of a rectangular house located in the yard in feet, and calculates and displays the time required to cut the grass in the thousand at the charge per unit of 2 foursquare feet per 2nd (nosotros presume that the part of the yard that is not covered by the firm is covered by grass and needs to exist cut). The computed time has to be given in Hours, Minutes, and Seconds. Your programme should also print the areas (length * width) of (i) the yard, (ii) the business firm and (iii) the grass surface area in both foursquare feet and square meter. Your program is also required to print the perimeters (ii * (length + width)) of (i) the m and (ii) the house in both feet and meter. Notation that 1 (pes) feet is equal to 0.3048 meter.
Currently whenever I attempt to compile my program it gives me the post-obit errors:
C:\Users\Britannia\Documents\assign2.c||In part 'main':|
C:\Users\Britannia\Documents\assign2.c|twenty|fault: 'perimter_yardFT' undeclared (start use in this function)|
C:\Users\Britannia\Documents\assign2.c|twenty|annotation: each undeclared identifier is reported simply once for each function it appears in|
C:\Users\Britannia\Documents\assign2.c|21|error: 'perimeter_yardM' undeclared (kickoff use in this function)|
C:\Users\Britannia\Documents\assign2.c|22|error: 'perimter_houseFT' undeclared (starting time use in this function)|
C:\Users\Britannia\Documents\assign2.c|22|error: 'houseleng' undeclared (first utilize in this role)|
C:\Users\Britannia\Documents\assign2.c|22|error: expected ')' earlier 'perimeter_yardFT'|
C:\Users\Britannia\Documents\assign2.c|23|error: 'perimter_houseM' undeclared (first utilize in this function)|
||=== Build failed: 6 error(due south), 0 warning(s) (0 minute(s), 0 second(s)) ===|
Information technology's telling me my variables are non alleged, withal I've alleged them in the get-go cake.
Homework Equations
The Endeavor at a Solution
#include <stdio.h> #include <math.h> // #include <stdlib.h> #define CONVERSIONCONSTANT 10.7639 int main() { float time, yardarea_FT, yardarea_M, housearea_FT, housearea_M, grassarea_FT, grassarea_M, yardlength, yardwidth, houselength, housewidth, perimeter_yardFT, perimter_yardM, perimeter_houseFT, perimeter_houseM; printf("Enter the yard length and width in feet in such order \n"); scanf("%f, %f \n", yardlength, yardwidth); printf("Enter the house length and width in feet in such gild \n"); scanf("%f, %f \n", houselength, housewidth); yardarea_FT = yardlength * yardwidth; yardarea_M = yardarea_FT * CONVERSIONCONSTANT; housearea_FT = houselength * housewidth; housearea_M = housearea_FT * CONVERSIONCONSTANT; grassarea_FT = yardarea_FT - housearea_FT; grassarea_M = grassarea_FT * CONVERSIONCONSTANT; perimter_yardFT = (yardlength + yardwidth) * 2; perimeter_yardM = (perimter_yardFT * CONVERSIONCONSTANT); perimter_houseFT = (houseleng perimeter_yardFT, perimter_yardM, perimeter_houseFT, perimeter_houseM;th + housewidth) * two; perimter_houseM = (perimter_houseFT * CONVERSIONCONSTANT); fourth dimension = grassarea_FT / 2; printf("The fourth dimension required to cut the grass in the yard is: \t %.2f", time); printf("The area of the yard in square anxiety is: \t%.2f", yardarea_FT); printf("The expanse of the yard in square meters is: \t%.2f", yardarea_M); printf("The area of the house in square feet is: \t%.2f", housearea_FT); printf("The area of the firm in square meters is: \t%.2f", housearea_M); printf("The area of the grass in square feet is: \t%.2f", grassarea_FT); printf("The area of the grass in square meters is: \t%.2f", grassarea_M); printf("The perimeter of the m in feet is: \t%.2f", perimeter_yardFT); printf("The perimeter of the 1000 in square meters is: \t%.2f", perimeter_yardM); printf("The perimeter of the house in anxiety is: \t%.2f", perimeter_houseFT); printf("The perimeter of the firm in square meters is: \t%.2f", perimeter_houseM); return 0; }
Another question I have is how tin I organize my program to look cleaner? I'm a rookie correct now with a calendar week of experience. And would this program even work if I were to get by my current problems?
Thanks.
Answers and Replies
You alleged a variable named perimeter_yardFT, but are using the variable above, which wasn't declared. Most of your errors seem to be inconsistencies between the declared variable names and the ones you really utilise, that have slightly dissimilar spellings.Mod note: Edited the following to remove spoiler tags and to put code in code tags
Homework Argument
Hello, currently I have this assignment:
Write a program by going through the 6 trouble solving steps that reads in the length and width of a rectangular one thousand in feet, the length and width of a rectangular house located in the yard in anxiety, and calculates and displays the time required to cutting the grass in the one thousand at the rate of 2 foursquare anxiety per second (nosotros assume that the function of the yard that is not covered by the house is covered by grass and needs to be cut). The computed time has to be given in Hours, Minutes, and Seconds. Your programme should also print the areas (length * width) of (i) the yard, (2) the house and (3) the grass area in both foursquare feet and square meter. Your program is as well required to print the perimeters (2 * (length + width)) of (i) the yard and (2) the firm in both feet and meter. Annotation that 1 (foot) anxiety is equal to 0.3048 meter.Currently whenever I try to compile my program it gives me the post-obit errors:
C:\Users\Britannia\Documents\assign2.c||In function 'main':|
C:\Users\Britannia\Documents\assign2.c|20|error: 'perimter_yardFT' undeclared (outset use in this function)|
Something that you are doing correct is to utilize meaninful names for your variables. Just make certain that y'all are consistent in how you spell each variable.
C:\Users\Britannia\Documents\assign2.c|20|notation: each undeclared identifier is reported only once for each function it appears in|
C:\Users\Britannia\Documents\assign2.c|21|error: 'perimeter_yardM' undeclared (first employ in this role)|
C:\Users\Britannia\Documents\assign2.c|22|error: 'perimter_houseFT' undeclared (first use in this function)|
C:\Users\Britannia\Documents\assign2.c|22|error: 'houseleng' undeclared (kickoff use in this part)|
C:\Users\Britannia\Documents\assign2.c|22|error: expected ')' before 'perimeter_yardFT'|
C:\Users\Britannia\Documents\assign2.c|23|error: 'perimter_houseM' undeclared (start use in this role)|
||=== Build failed: half-dozen error(s), 0 alert(s) (0 infinitesimal(s), 0 second(southward)) ===|It'due south telling me my variables are not alleged, however I've declared them in the beginning cake.
Homework Equations
The Attempt at a Solution
I've read something that said C can but have variables alleged in the starting block, notwithstanding is that not what I've done?#include <stdio.h> #include <math.h> // #include <stdlib.h> #define CONVERSIONCONSTANT 10.7639 int main() { float fourth dimension, yardarea_FT, yardarea_M, housearea_FT, housearea_M, grassarea_FT, grassarea_M, yardlength, yardwidth, houselength, housewidth, perimeter_yardFT, perimter_yardM, perimeter_houseFT, perimeter_houseM; printf("Enter the g length and width in feet in such social club \northward"); scanf("%f, %f \n", yardlength, yardwidth); printf("Enter the business firm length and width in anxiety in such order \n"); scanf("%f, %f \northward", houselength, housewidth); yardarea_FT = yardlength * yardwidth; yardarea_M = yardarea_FT * CONVERSIONCONSTANT; housearea_FT = houselength * housewidth; housearea_M = housearea_FT * CONVERSIONCONSTANT; grassarea_FT = yardarea_FT - housearea_FT; grassarea_M = grassarea_FT * CONVERSIONCONSTANT; perimter_yardFT = (yardlength + yardwidth) * 2; perimeter_yardM = (perimter_yardFT * CONVERSIONCONSTANT); perimter_houseFT = (houseleng perimeter_yardFT, perimter_yardM, perimeter_houseFT, perimeter_houseM;th + housewidth) * 2; perimter_houseM = (perimter_houseFT * CONVERSIONCONSTANT); time = grassarea_FT / 2; printf("The time required to cut the grass in the yard is: \t %.2f", time); printf("The expanse of the yard in foursquare anxiety is: \t%.2f", yardarea_FT); printf("The area of the yard in square meters is: \t%.2f", yardarea_M); printf("The area of the firm in foursquare feet is: \t%.2f", housearea_FT); printf("The surface area of the house in square meters is: \t%.2f", housearea_M); printf("The area of the grass in square feet is: \t%.2f", grassarea_FT); printf("The surface area of the grass in square meters is: \t%.2f", grassarea_M); printf("The perimeter of the 1000 in feet is: \t%.2f", perimeter_yardFT); printf("The perimeter of the one thousand in foursquare meters is: \t%.2f", perimeter_yardM); printf("The perimeter of the firm in feet is: \t%.2f", perimeter_houseFT); printf("The perimeter of the firm in square meters is: \t%.2f", perimeter_houseM); return 0; }
Another question I have is how can I organize my program to look cleaner? I'm a rookie right now with a week of experience. And would this program even work if I were to get past my current bug?
Thanks.
When you go input from the user, as in the line below, the best thing to do is to input one variable at a time. In the following line of lawmaking, because of the style scanf works, the user will have to enter a number, followed by a comma, and and then some other number.
Make it piece of cake on the user by prompting for a unmarried value, and so inputting that value, followed by echoing (printing) that value over again so that the user can see that his/her input was successfully taken by the program.
scanf("%f, %f \north", yardlength, yardwidth);
The post-obit lines contain several errors, including undeclared variables. I have no idea what you're trying to do in the third line below.
perimter_yardFT = (yardlength + yardwidth) * ii; perimeter_yardM = (perimter_yardFT * CONVERSIONCONSTANT); perimter_houseFT = (houseleng perimeter_yardFT, perimter_yardM, perimeter_houseFT, perimeter_houseM;th + housewidth) * 2; perimter_houseM = (perimter_houseFT * CONVERSIONCONSTANT);
The control string in each of your printf() calls should end with a \n grapheme so that output shows upwardly on split lines.
printf("The fourth dimension required to cutting the grass in the one thousand is: \t %.2f", fourth dimension);
One more than thing -- please stop using spoiler tags...
I'm a picayune embarrassed I didn't even realize the variables were simply spelled incorrectly...
The line:
perimter_houseFT =(houseleng perimeter_yardFT, perimter_yardM, perimeter_houseFT, perimeter_houseM;th + housewidth)*two;
perimeter_houseFT = (houselength + housewidth) * 2;
How it progressed into the first line I have no clue.
Anyhow, I've managed to compile the program successfully without any errors, however when I run the programme it volition close after the user inputs the showtime value.
Hither is my new lawmaking:
#include <stdio.h> #include <math.h> #define CONVERSIONCONSTANT 10.7639 int primary() { float time, yardarea_FT, yardarea_M, housearea_FT, housearea_M, grassarea_FT, grassarea_M, yardlength, yardwidth, houselength, housewidth, perimeter_yardFT, perimeter_yardM, perimeter_houseFT, perimeter_houseM; printf("Enter the thou length in feet\due north"); scanf("%f \north", yardlength); printf("You entered: %f\n", yardlength); printf("Enter the 1000 width in feet\north"); scanf("%f \n", yardwidth); printf("You entered: %f\due north", yardwidth); printf("Enter the firm length in feet\n"); scanf("%f \n", houselength); printf("You entered: %f\n", houselength); printf("Enter the house width in feet\n"); scanf("%f \n", housewidth); yardarea_FT = yardlength * yardwidth; yardarea_M = yardarea_FT * CONVERSIONCONSTANT; housearea_FT = houselength * housewidth; housearea_M = housearea_FT * CONVERSIONCONSTANT; grassarea_FT = yardarea_FT - housearea_FT; grassarea_M = grassarea_FT * CONVERSIONCONSTANT; perimeter_yardFT = (yardlength + yardwidth) * 2; perimeter_yardM = (perimeter_yardFT * CONVERSIONCONSTANT); perimeter_houseFT = (houselength + housewidth) * 2; perimeter_houseM = (perimeter_houseFT * CONVERSIONCONSTANT); time = grassarea_FT / 2; printf("The time required to cut the grass in the g is: \t %.2f\northward", time); printf("The area of the yard in foursquare feet is: \t%.2f\northward", yardarea_FT); printf("The expanse of the yard in foursquare meters is: \t%.2f\due north", yardarea_M); printf("The area of the house in square anxiety is: \t%.2f\n", housearea_FT); printf("The expanse of the house in square meters is: \t%.2f\n", housearea_M); printf("The area of the grass in square feet is: \t%.2f\n", grassarea_FT); printf("The surface area of the grass in square meters is: \t%.2f\n", grassarea_M); printf("The perimeter of the yard in feet is: \t%.2f\northward", perimeter_yardFT); printf("The perimeter of the yard in square meters is: \t%.2f\northward", perimeter_yardM); printf("The perimeter of the firm in feet is: \t%.2f\northward", perimeter_houseFT); printf("The perimeter of the business firm in square meters is: \t%.2f\n", perimeter_houseM); return 0; }
The CMD prompt shows "Process returned -1073741819 <0xC0000005>"
(I've removed the intervening printf() calls.scanf("%f \due north", yardlength); scanf("%f \due north", yardwidth); scanf("%f \n", houselength); scanf("%f \n", housewidth);
The first one should look like this:
scanf("%f", &yardlength);
The variable proper name appears with a preceding & character. scanf() requires the address of a memory location into which it stores the input value.
Alter the other 3 calls to scanf() in a similar way.
If you run your program in its own control prompt window, the program will run and the output will remain displayed. If you run your plan in a debugger (I'm thinking Visual Studio, which might not be what you lot're using), the debugger opens a separate command window, but closes it when your program is washed, and so the window opens and closes so fast it's hard to tell what's happening.
Another thing you can do is to add together another phone call to scanf() or other input function almost the bottom of your code. The only purpose of this input is to keep the program from exiting. You don't need to do anything with the input value.
But out of curiosity, practise you think C is a good plan to learn start? I was told otherwise since it's the closest high level language to Automobile Language that it would end up confusing me. (And apparently memory direction in C is painful to deal with?) Then far I'm doing fine in the form.
C has been chosen a "loftier-level assembly language" (not motorcar language, which is all numbers). However, it'due south a lot higher level than associates linguistic communication.Simply out of marvel, do you think C is a good program to learn offset? I was told otherwise since it's the closest loftier level language to Car Language that information technology would terminate up disruptive me. (And plainly retentivity direction in C is painful to deal with?) So far I'grand doing fine in the course.
IMO, C is a proficient language to offset with. Although it doesn't have some of the features of more modernistic languages, such equally object-oriented programming (OOP), inheritance, polymorphism, and the similar, learning information technology gets you lot off to a good start at procedural programming and the use of control structures such as for and while loops, and branching structures such is if ... else and switch. Many of the newer languages derive from C to a lesser of greater extent. For instance, C++, C#, Java, JavaScript, Python, and probably a few others. Even Matlab builds on C, particularly in the similarity of how information technology does output.
Once y'all get a skillful handle on C, learning other languages will exist a picayune easier. Other languages, such as C++ and Coffee, that feature OO aspects, take a while to learn, but you lot won't accept to offset completely from scratch.
C has been chosen a "high-level assembly language" (non auto language, which is all numbers). However, it's a lot college level than assembly language.IMO, C is a good linguistic communication to offset with. Although it doesn't have some of the features of more than modern languages, such as object-oriented programming (OOP), inheritance, polymorphism, and the like, learning it gets you lot off to a practiced start at procedural programming and the apply of control structures such as for and while loops, and branching structures such is if ... else and switch. Many of the newer languages derive from C to a lesser of greater extent. For instance, C++, C#, Java, JavaScript, Python, and probably a few others. Even Matlab builds on C, particularly in the similarity of how it does output.
Once you get a good handle on C, learning other languages will be a little easier. Other languages, such as C++ and Coffee, that characteristic OO aspects, take a while to learn, but you won't accept to start completely from scratch.
I am really enjoying it right now, as I feel similar I am understanding alot more well-nigh the reckoner as well. Hopefully I can transition into either C++ or java one time I've had my make full of C, every bit it seems like those two are very widely used. The only consequence right now I'1000 imposed with, is that it feels like all my professors / TA's are relatively worthless. They're useful for reference, merely they don't seem to teach anything properly. Is informatics simply picking everything up on your ain? I just had a lab where the TA'south left a trouble for u.s.a. to solve, just they didn't teach anything. I had no idea what to do still it was being graded for participation.
The role of the TA is commonly less equally a teacher and more equally an assistant, fielding specific questions and the like. I took a summer course in Fortran at a nearby, well-known university (it was long ago), non as part of any caste requirements, merely for my own personal knowledge. In the starting time form session, the prof admitted that he didn't know much about Fortran, and he didn't know much about the new operating system that had been installed (VAX VMS). He spent a good part of the first class period chit-chatting with some students that he apparently already knew. Afterwards the class was over (an hr and a half), the simply affair on the lath was something unrelated to Fortran scrawled diagonally across ane of the blackboards. I decided to drop that class, and wound up taking information technology the following summertime.I am really enjoying it correct now, as I feel like I am understanding alot more almost the computer as well. Hopefully I can transition into either C++ or java once I've had my fill of C, as it seems like those 2 are very widely used. The only issue right now I'1000 imposed with, is that it feels like all my professors / TA's are relatively worthless. They're useful for reference, but they don't seem to teach annihilation properly. Is computer science just picking everything up on your own? I just had a lab where the TA'due south left a problem for us to solve, only they didn't teach anything. I had no idea what to do still it was being graded for participation.
Related Threads on C program to calculate area and a few other things
- Last Post

- Last Mail service
- Concluding Post

- Final Post
- Concluding Post

- Concluding Post
- Last Post
- Last Post

- Last Post
- Terminal Mail service

- Forums
- Homework Help
- Technology and Comp Sci Homework Assistance
Source: https://www.physicsforums.com/threads/c-program-to-calculate-area-and-a-few-other-things.835296/
Post a Comment for "Write a Program That Reads in the Length and the Width of a Rectangular Yard"