- #1
Arnoldjavs3
- 191
- 3
Mod note: Edited the following to remove spoiler tags and to put code in code tags
Hi, currently I have this assignment:
Write a program by going through the 6 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 yard at the rate of 2 square feet per second (we assume that the part 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 program should also print the areas (length * width) of (i) the yard, (ii) the house and (iii) the grass area in both square feet and square meter. Your program is also required to print the perimeters (2 * (length + width)) of (i) the yard and (ii) the house in both feet and meter. Note that 1 (foot) feet is equal to 0.3048 meter.
Currently whenever I attempt to compile my program it gives me the following errors:
C:\Users\Britannia\Documents\assign2.c||In function 'main':|
C:\Users\Britannia\Documents\assign2.c|20|error: 'perimter_yardFT' undeclared (first use in this function)|
C:\Users\Britannia\Documents\assign2.c|20|note: 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 use in this function)|
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 (first use in this function)|
C:\Users\Britannia\Documents\assign2.c|22|error: expected ')' before 'perimeter_yardFT'|
C:\Users\Britannia\Documents\assign2.c|23|error: 'perimter_houseM' undeclared (first use in this function)|
||=== Build failed: 6 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
It's telling me my variables are not declared, however I've declared them in the beginning block.
I've read something that said C can only have variables declared in the starting block, however is that not what I've done?
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 issues?
Thanks.
Homework Statement
Hi, currently I have this assignment:
Write a program by going through the 6 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 yard at the rate of 2 square feet per second (we assume that the part 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 program should also print the areas (length * width) of (i) the yard, (ii) the house and (iii) the grass area in both square feet and square meter. Your program is also required to print the perimeters (2 * (length + width)) of (i) the yard and (ii) the house in both feet and meter. Note that 1 (foot) feet is equal to 0.3048 meter.
Currently whenever I attempt to compile my program it gives me the following errors:
C:\Users\Britannia\Documents\assign2.c||In function 'main':|
C:\Users\Britannia\Documents\assign2.c|20|error: 'perimter_yardFT' undeclared (first use in this function)|
C:\Users\Britannia\Documents\assign2.c|20|note: 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 use in this function)|
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 (first use in this function)|
C:\Users\Britannia\Documents\assign2.c|22|error: expected ')' before 'perimeter_yardFT'|
C:\Users\Britannia\Documents\assign2.c|23|error: 'perimter_houseM' undeclared (first use in this function)|
||=== Build failed: 6 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
It's telling me my variables are not declared, however I've declared them in the beginning block.
Homework Equations
The Attempt at a Solution
C:
#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 order \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) * 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 area of the yard in square feet is: \t%.2f", yardarea_FT);
printf("The area 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 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 area of the grass in square meters is: \t%.2f", grassarea_M);
printf("The perimeter of the yard in feet is: \t%.2f", perimeter_yardFT);
printf("The perimeter of the yard in square meters is: \t%.2f", perimeter_yardM);
printf("The perimeter of the house in feet is: \t%.2f", perimeter_houseFT);
printf("The perimeter of the house 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 issues?
Thanks.
Last edited by a moderator: