I am taking a beginner comp sci class and I am having a weird issue with my program that I am writing. The program is meant to calculate how much grass needs to be cut on a lawn by taking the area of the yard and subtracting the are of the house.
Here is the code:
I will put in values such as:
30 40
10 20
and instead of getting 1000 as my answer I will get a value of something like: -24615476 square feet will need to be cut. Even more perplexing is the fact that my output is different each time I run the program.
If somebody could find the problem with my code I would be super grateful!
Here is the code:
Code:
#include <stdio.h>
int main()
{
int yardlength;
int yardwidth;
int houselength;
int housewidth;
int grasssize;
grasssize = yardlength * yardwidth - houselength * housewidth;
scanf("%d%d", &yardlength, &yardwidth);
scanf("%d%d", &houselength, &housewidth);
printf("%d square feet will need to be cut.\n", grasssize);
return 0;
}
30 40
10 20
and instead of getting 1000 as my answer I will get a value of something like: -24615476 square feet will need to be cut. Even more perplexing is the fact that my output is different each time I run the program.
If somebody could find the problem with my code I would be super grateful!










