| Please tell me where I messed up In the Code below i have written for my class i am unsure what I have done wrong. This is suppose to be a calculator for different shapes. This is the instructions from my professor
"If the user enters a character other than t, c, s, or r, tell him that he has to enter one of those four characters, and then have your program exit. On the other hand, if the user enters a t, you then need to prompt him to enter the base and the height of the triangle. If he enters a c, you need to prompt him to enter the radius of the circle. If he enters an s, you need to prompt him to enter the length of the side of the square. And if he enters an r, you need to prompt him to enter the length and the width of the rectangle." #include <stdio.h>
#include <math.h> void main () { double num, num2, total;
char shape;
char enterkey; printf ("Please enter a shape:");
scanf ("%c", &shape);
if (shape=='t'){
printf ("\nPlease enter the base of the triangle:");
scanf ("%d", &num);
printf ("\nPlease enter the height of the triangle:");
scanf ("%d", &num2);
total= 0.5 * num * num2;
printf ("area= 0.5 * %d * %d = %d", num, num2, total);
}else if (shape=='c'){
printf ("\nPlease enter the radius of the circle:");
scanf ("%d", &num);
total=2 * 3.14 * num;
printf ("area= 2 * 3.14 * %d = %d", num, total);
}else if (shape=='s'){
printf ("\nPlease enter the side of the square:");
scanf ("%d", &num);
total= 4 * num;
printf ("area= 4 * %d = %d", num, total);
}else if (shape=='r'){
printf ("\nPlease enter the length of the rectangle:");
scanf ("%d", &num);
printf ("\nPlease enter the height of the rectangle:");
scanf ("%d", &num2);
total = num * num2;
printf ("area= %d * %d = %d", num, num2, total);
}else {
printf ("\n I do not know that letter that was inputed please try again!");
}
printf ("\n\n");
scanf ("%c", &enterkey);
}
Last edited by hnkplaya : 06-28-2007 at 11:15 AM.
|