When I first started messing around with your code, I saw that you actualy wanted two things out of the same code portion, from your description it looks like a nested loop where it writes every lumber size possible.
Here is a version where it loops through the lumber sizes:
Code:
#include <stdio.h>
int main()
{
int base, height, crosssection;
float moment, sectionmod;
for(base = 2; base <= 10; base +=2)
{
for(height = 2; height <= 12; height +=2)
{
crosssection=base*height;
moment=crosssection/12.0;
sectionmod=crosssection/6.0;
printf("\n");
printf("\tLumber size (%dx%d):\n", base, height);
printf("\t\t %d Cross-sectional area\n", crosssection);
printf("\t\t %.3f Momentof inertia \n", moment);
printf("\t\t %.3f Section modulous\n", sectionmod);
}
}
return 0;
}
But from your code, it looks like there shuld be some user interaction...
Here is a version where theres user interaction:
Code:
#include <stdio.h>
int main()
{
int base=0, height=0, crosssection=0;
float moment=0.0, sectionmod=0.0;
while((base <= 0 && height <=0) || (base > 10 && height > 12))
{
printf("Please enter base in form of: B:H\t");
fflush(stdout);
if(2 > fscanf(stdin, "%d:%d", &base, &height))
{
printf("Error, you didn't provide B:H\n");
continue;
}
if(base <= 0 || base >10)
{
printf("Error, base must be between 1 and 10.\n");
continue;
}
if(height <= 0 || height > 12)
{
printf("Error, height must be between 1 and 12.\n");
continue;
}
}
crosssection=base*height;
moment=crosssection/12.0;
sectionmod=crosssection/6.0;
printf("\tLumber size (%dx%d):\n", base, height);
printf("\t\t %d Cross-sectional area\n", crosssection);
printf("\t\t %.3f Momentof inertia \n", moment);
printf("\t\t %.3f Section modulous\n", sectionmod);
return 0;
}
I don't knwo which one you wanted, or if it was a combination of them both... But for starters you can look at my two examples and see if any of them fits you.