Greetings. Looking for some help learning what the problem is here. I am using an OLD Programming in C book (25yrs old, in fact), and I dunno if anything may have changed. The compiler I have been using is CodingGround.
My HW assignment is as follows:
"Calculate area of a house (up to four rectangle rooms)".
Seems simple enough, but I am failing left, right and center. Trying to set up an input to let user enter # of rooms, then ask L & W measurements for each room until entries = rooms and then add up each room's area and print it out.
First attempt:
Code:
#include <stdio.h>
main ()
{
int i, Rm;
int T_area = 0;
float Length, Width, Area;
printf("How many rooms to include in calculation?");
scanf("%d", &Rm);
For(i = 1; i <= Rm; ++i)
{
printf("Enter Length for Room #%d:",i);
scanf("%f", &Length);
printf("Enter Width for Room #%d:",i);
scanf("%f", &Width);
Area = Length * Width;
T_area = T_area + Area;
}
printf("Total area of rooms = %f", T_area);
return 0;
}
Fail.
Second attempt (commented out For loop, went all in on While):
Code:
#include <stdio.h>
main ()
{
int i, Rm;
int T_area = 0;
float Length, Width, Area;
printf("How many rooms to include in calculation?");
scanf("%d", &Rm);
/*For(i = 1; i <= Rm; ++i)*/
i=1;
While (i <= Rm)
{
printf("Enter Length for Room #%d:",i);
scanf("%f", &Length);
printf("Enter Width for Room #%d:",i);
scanf("%f", &Width);
Area = Length * Width;
T_area = T_area + Area;
++i
}
printf("Total area of rooms = %f", T_area);
return 0;
}
Double fail.
Both attempts give same errors:
Code:
gcc -o main *.cgcc -o main *.c
expected ; before { (line 12)
While tweaking this around, i occasionally got some other random error...compiler seems a little...moody. If there is a better one i am all about switchin...as long as its free, yo.
Thanks to anyone who can lend some help...i think i am a few pointers away from getting on top of this and start learning from successes, rather than drinking due to failures.
Cheers.