Hi all, i'm new to programming. This is a code to calculate the areas of different shapes. The user should choose the shape, pick whether they want the measurement in cm or m, then be asked how many shapes they are calculating the area of.

I am wondering whether I can make this code with with the for loops in the functions, or will I have to move them back up to the main body.

I have also tried making the return types void.

SQUARE:Will ask how many shapes you want to calculate the area of but will only calculate the area for one regardless

CIRCLE/TRIANGLE:Will ask if you want the answer in cm or m but will then loop back to the main menu.

Sorry this is such a long code!

Code:double squareCM (double a,double b); double squareM (double a, double b); double circleCM (double a); double circleM (double a); double triangleCM (double a,double b); double triangleM (double a, double b); double a,b; main() { char ch,pa; while(ch!='0') { system("cls"); printf("\n 1 - Rectangle"); printf("\n 2 - Circle"); printf("\n 3 - Triangle"); printf("\n 0 - Exit"); printf("\nPlease enter your choice"); ch=getche(); system("cls"); if(ch=='1') { printf("\n 1 - Answer in CM"); printf("\n 2 - Answer in M"); printf("\n 0 - Exit"); printf("\n Please enter your choice"); pa=getche(); system("cls"); if(pa=='1') { squareCM(a,b); } else if(pa=='2') { squareM(a,b); } } else if(ch=='2') { printf("\n 1 - Answer in CM"); printf("\n 2 - Answer in M"); printf("\n 0 - Exit"); printf("\n Please enter your choice"); pa=getche(); system("cls"); if(pa=='1') { circleCM(a); } else if(pa=='2') { circleM(a); } } else if(ch=='3') { printf("\n 1 - Answer in CM"); printf("\n 2 - Answer in M"); printf("\n 0 - Exit"); printf("\n Please enter your choice"); pa=getche(); system("cls"); if(pa=='1') { triangleCM(a,b); } else if(pa=='2') { triangleM(a,b); } } } } double squareCM(double a,double b) { int counter,d; printf("Please enter the amount of shapes you are calculating the area of\n"); scanf("%d",&counter); for(d=1; d<=counter; d++) { printf("Please enter length of rectangle\n"); scanf("%lf",&a); printf("Please enter width of rectangle\n"); scanf("%lf",&b); double num; num=(a*b); return num; } } double squareM (double a,double b) { double num; num=((a*b)/100); return num; int counter,d; printf("Please enter the amount of shapes you are calculating the area of\n"); scanf("%d",&counter); for(d=1; d<=counter; d++) { printf("Please enter length of rectangle\n"); scanf("%lf",&a); printf("Please enter width of rectangle\n"); scanf("%lf",&b); printf("%lf\n",squareM(a,b)); getch(); } } double circleCM (double a) { double num; double pi; num=(pi*a*a); return num; int counter,d; double area; printf("Please enter the amount of shapes you are calculating the area of\n"); scanf("%d\n",&counter); for(d=1; d<=counter; d++) { printf("Please enter the radius of the circle\n"); scanf("%lf",a); area = pi*a*a; printf("The area of the circle is: %lf\n", circleCM(a)); getch(); } } double circleM (double a) { double num; double pi; num=((pi*a*a)/100); return num; int counter,d; double area; printf("Please enter the amount of shapes you are calculating the area of\n"); scanf("%d\n",&counter); for(d=1; d<=counter; d++) { printf("Please enter the radius of the circle\n"); scanf("%lf",a); area = ((pi*a*a)/100); printf("The area of the circle is: %lf\n", circleM(a)); getch(); } } double triangleCM (double a, double b) { double num; num=((a*b)*0.5); return num; int counter,d; double area; printf("Please enter the amount of shapes you are calculating the area of\n"); scanf("%d\n",&counter); for(d=1; d<=counter; d++) { printf("Please enter the base of your triangle\n"); scanf("%lf\n",&a); printf("Please enter the height of your triangle\n"); scanf("%lf\n", &b); area=(a*b)*0.5; printf("The area of the triangle is: %lf\n",triangleCM(a,b)); getch(); } } double triangleM (double a, double b) { double num; num=(((a*b)*0.5)/100); return num; int counter, d; double area; printf("Please enter the amount of shapes you are calculating the area of\n"); scanf("%d\n",&counter); for(d=1; d<=counter; d++) { printf("Please enter the base of your triangle\n"); scanf("%lf",&a); printf("Please enter the height of your triangle\n"); scanf("%lf", &b); area=(((a*b)*0.5)/100); printf("The area of the triangle is: %lf\n",triangleM(a,b)); getch(); } }

Thanks,

Katie