speedy 5 your suggestion of use the switch statement was great. thank you
i hadn't thought about it because it hasn't been tought in my class yet.
as for EOF it means end of file and exits the program.
now i got mostly everything down i still have one problem
im suppose to prompt an error message when the user doesnt give a interger when asking for the height, width, side ....etc...
what should i use?
and when i enter things other than intergers the program would just keep looping forever.
one sample output i need is when the use enters triangle and gets an error message and is prompt again
enter again. what do i need for it statement do i need for it to do that and stop looping?
thanks a million
clear
Code:
#include <stdio.h>
#define PI 3.14
void main (){
int chose = 0;
int rwidth = 0;
int rheight = 0;
int rarea = 0;
int rperi = 0;
int side = 0;
int sarea = 0;
int speri = 0;
int radius = 0;
double carea = 0;
double cperi = 0;
int base =0;
int rside = 0;
int lside = 0;
int tarea = 0;
int tperi =0;
int theight = 0;
printf("Please choose 1-5 to calculate\n");
printf("the area and perimeter/circumference\n");
printf("of the various geometric shapes.\n");
do {
printf("1. Rectangle\n");
printf("2. Square\n");
printf("3. Circle\n");
printf("4. Triangle\n");
printf("5. Exit (or EOF, Control+Z)\n");
printf("Enter a value between 1 and 5: ");
scanf("%d", &chose);
switch (chose)
{
case (1) : printf("Please enter the width: ");
scanf("%d", &rwidth);
printf("Please enter the height: ");
scanf("%d",&rheight);
rarea = rwidth * rheight;
rperi = 2 * (rwidth * rheight);
printf("The area of the rectangle is %d.\n", rarea);
printf("The perimeter of the rectangle is %d.\n", rperi);
break;
case (2) : printf("Please enter the side: ");
scanf("%d", &side);
sarea = side * 4;
speri = (side * side);
printf("The area of the square is %d.\n", sarea);
printf("The perimeter of the square is %d.\n", speri);
break;
case (3) : printf("Please enter the radius: ");
scanf("%d", &radius);
carea = PI * radius * radius;
cperi = 2 * PI * radius;
printf("The area of the cirlce is %.2f.\n", carea);
printf("The circumference of the circle is %.2f.\n", cperi);
break;
case (4) : printf("Please enter the base: ");
scanf("%d",&base);
printf("Pleare enter the left side: ");
scanf("%d", &lside);
printf("Please enter the right side: ");
scanf("%d",&rside);
printf("Please enter the height: ");
scanf("%d", &theight);
tperi = base + lside + rside;
tarea = (base * theight) / 2;
printf("The area of the triangle is %d.\n", tarea);
printf("The perimeter of the triangle is %d.\n", tperi);
break;
case (5) : EOF;
break;
default : printf("Invalid choice entered.\n");
printf("Please enter a value between 1 and 5\n");
break;
}
}
while (chose != 5);
}