### NEED HELP. My programme wont run properly. DEADLINE TODAY . HELP ME PLEASE.

Hi Everyone. IN NEED OF HELP ASAP ! my deadline is today and im having trouble with this simple programme. i just could not figure out the problem. after the second switch, the programme closes. HELP ME .

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <math.h>
#define PI 3.1416
void main (void)
{
int choice;
char choiceA, choiceB, choiceC;
printf("Geometry Calculator\n");
printf("This programme calculates the area, volume and surface area of various shapes.\n\n");
printf("1.Area\n");
printf("2.Surface Area\n");
printf("3.Volume\n");
printf("0.Exit\n");
printf("Enter Choice: ");

scanf("%d", &choice);

switch (choice)
{
case 1:
printf("A. Circle\n");
printf("B. Triangle\n");
printf("C. Square\n");
printf("D. Rectangle\n");

scanf("%c", &choiceA);

switch (choiceA)
{
case 'A':
printf("Enter the radius of the circle (in cm): ");
{

printf("The area of the circle: %f cm sq", Area);
}
else
{
}
break;
case 'B':
printf("Enter the base length of the triangle (in cm): ");
scanf("f", &BaseLength);
printf("Enter the height of the triangle (in cm): ");
scanf("f", &Height);
if(BaseLength > 0 && Height >0)
{
Area = (1.0/2.0) * BaseLength * Height;

printf("The area of the triangle: %f cm sq", Area);
}
else
{
printf("Invalid Base Length or Height or Both. (Make sure values are positive)");
}
break;
case 'C':
printf("Enter the length of the square: ");
scanf("f", &Length);
if(Length > 0)
{
Area = pow(Length,2);

printf("The area of the square: %f cm sq", Area);
}
else
{
printf("Invalid Length. (Make sure the value is positive)");
}
break;
case 'D':
printf("Enter the base length of the rectangle (in cm): ");
scanf("%f", &BaseLength);
printf("Enter the height of the rectangle (in cm): ");
scanf("%f", &Height);
if(BaseLength > 0 && Height > 0)
{
Area = BaseLength * Height;

printf("The area of the rectangle: %f cm sq", Area);
}
else
{
printf("Invalid Base Length or Height or Both. (Make sure values are positive)");
}
break;
default :
printf("Unknown Choice\n");
}
break;
case 2:
printf("A. Sphere\n");
printf("B. Cylinder\n");
printf("C. Cube\n");
printf("D. Rectangular Prism\n");

scanf("%c", &choiceB);

switch(choiceB)
{
case 'A':
printf("Enter the radius of the sphere (in cm): ");
{
SurfaceArea = 4 * PI * pow(Radius,2);

printf("The surface area of the sphere: %f cm sq", SurfaceArea);
}
else
{
}
break;
case 'B':
printf("Enter the radius of the cylinder (in cm): ");
printf("Enter the height of the cylinder (in cm): ");
scanf("%f", &Height);
if(Radius > 0 && Height > 0)
{
SurfaceArea = ( 2 * PI * pow(Radius,2)) + ( 2 * PI * Radius * Height);

printf("The surface area of the cylinder: %f cm sq", SurfaceArea);
}
else
{
printf("Invalid Radius or Height or Both. (Make sure values are positive)");
}
break;
case 'C':
printf("Enter the base length of the cube (in cm): ");
scanf("%f", &BaseLength);
{
SurfaceArea = 6 * pow(BaseLength,2);

printf("The surface area of the cube: %f cm sq", SurfaceArea);
}
else
{
printf("Invalid Base Length. (Make sure Base Length is positive)");
}
break;
case 'D':
printf("Enter the length of the rectangular prism (in cm): ");
scanf("%f", &Length);
printf("Enter the breadth of the rectangular prism (in cm): ");
printf("Enter the height of the rectangular prism (in cm): ");
scanf("%f", &Height);
if(Length > 0 && Breadth > 0 && Height > 0)
{
SurfaceArea = (( 2 * Length * Breadth ) + ( 2 * Breadth * Height ) + ( 2 * Length * Height ));

printf("The surface area of the rectangular prism: %f cm sq", SurfaceArea);
}
else
{
printf("Invalid Length, Breadth or Height or ALL. (Make sure values are postive)");
}
break;
default:
printf("Unknown Choice\n");
}
break;
case 3:
printf("A. Cube\n");
printf("B. Cylinder\n");
printf("C. Cone\n");
printf("D. Sphere\n");

scanf("%c", &choiceC);

switch(choiceC)
{
case 'A':
printf("Enter the base length of the cube (in cm): ");
scanf("%d", &BaseLength);
if(BaseLength > 0)
{
Volume = pow(BaseLength,3);

printf("The volume of the cube: &f cm cube", Volume);
}
else
{
printf("Invalid Base Length. (Make sure base length is positive)");
}
break;
case 'B':
printf("Enter the radius of the cylinder (in cm): ");
printf("Enter the height of the cylinder (in cm): ");
scanf("%f", &Height);
if(Radius > 0 && Height > 0)
{
Volume = PI * pow(Radius,2) * Height;

printf("The volume of the cylinder: %d cm cube");
}
else
{
printf("Invalid Radius or Height or Both. (Make sure values are positive)");
}
break;
case 'C':
printf("Enter the radius of the cone (in cm): ");
printf("Enter the height of the cone (in cm): ");
scanf("%f", &Height);
if(Radius > 0 && Height > 0)
{
Volume = (1.0/3.0) * pow(Radius,2) * PI * Height;

printf("The volume of the cone: %f cm cube", Volume);
}
else
{
printf("Invalid Height or Radius or Both. (Make sure values are positive)");
}
break;
case 'D':
printf("Enter the radius of the sphere (in cm): ");
{

printf("The volume of the sphere: %f cm cube", Volume);
}
else
{
}
break;
default:
printf("Unknown Choice\n");
}
break;
case 0:
printf("Goodbye! Thank you for using this programme!\n");
break;
default:
printf("Unknown Choice\n");
}
getch();
exit(0);
}
Last edited on
first off: YOU CAN'T DECLARE MAIN AS VOID.

proper declaration:

 ``1234`` ``````int main() { return 0; }``````

Why a your code would even compile is beyond me, but never ever declare main as void.
Last edited on
it compiles with void main (void). im not taught to do otherwise?
im a beginner . so whats wrong declaring main as void?
Last edited on
Your problem comes from the fact you do not tell you program to loop back at the beginning of the menu if the choice was not no exit.

To correct that you can use a while loop around your menu:
 ``1234567891011`` ``````int main (void) { // variables declaration bool ExitProgram = false; while( ExitProgram == false ) { // your current menu code // for case 0, add "ExitProgram = true;" before break } // ... }``````
Last edited on
i have decided to abandon this program and create a new program instead. i will make a simpler program. the requirements were to only include if-else and switch. i may have been too adventurous and in the end myself up in deep trouble. LOL . thanks for replying me anyway. sorry to waste your time.
Topic archived. No new replies allowed.