### Switch case missing "{" "}"

Hi here's my program i got an error where it's expecting a "{" or a "}" but i do not know where to place them can someone please help me?

my goal here is to choose from a switch case (ch)
1= circle, 2 =Square, 3= Triangle, and 4 = exit which our prof asked us to return to main. within each switch (ch) there's another switch, switch(chc) for circle and switch(chs) for square and switch(cht) for triangle. Where do i have to put the "{" and "}"? Thanks in advance

 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 #include #include #include #define pi 3.1416 main() { int ch=0,chc=0,cht=0,chs=0; float r=0,C=0,Ac=0,Vc=0,S=0,Ps=0,As=0,Vs=0,Pt=0,b=0,h=0,At=0,Vt=0; do{ system("cls"); printf("Geometric Formulas"); printf("\n1. Circle"); printf("\n2. Square"); printf("\n3. Triangle"); printf("\n4. Exit"); printf("\n \n"); printf("\nChoice: "); scanf("%d", &ch); switch(ch){ case 1: //circle do{ system("cls"); printf("Circle"); printf("\n1. Circumference"); printf("\n2. Area"); printf("\n3. Volume"); printf("\n4. Exit"); printf("\n \n"); printf("\nChoice: "); scanf("%d", &chc); switch(chc){ case 1: //Circumference system("cls"); printf("This Computes the circumference of a circle"); printf("\n\n"); printf("Enter Radius"); scanf("%f", &r); C=2*pi*r; printf("The Circumference of a circle with radius %f is %f",r,C); system("Pause"); break; case 2: //Area system("cls"); printf("This Computes the Area of a circle"); printf("\n\n"); printf("Enter Radius"); scanf("%f", &r); Ac= 2*pi*r*r; printf("The Area of a circle with radius %f is %f",r,Ac); system("Pause"); break; case 3: //Volume printf("This Computes the Volume of a Sphere"); printf("\n\n"); printf("Enter Radius"); scanf("%f",&r); Vc= (4/3)*(pi*r*r*r); printf("The Volume of a sphere with radius %f is %f",r,Vc); break; case 4: //exit from chc return main(); default: printf("The Operation cannot be done"); break; }while (chc!=4); break; case 2: //square do{ system("cls"); printf("Square"); printf("\n1. Perimeter"); printf("\n2. Area"); printf("\n3. Volume"); printf("\n4. Exit"); printf("\n \n"); printf("\nChoice: "); scanf("%d", &chs); switch(chs){ case 1: //Perimeter Square system("cls"); printf("This Computes the Perimeter of a Square"); printf("\n\n"); printf("Enter Length of Side"); scanf("%f", &S); Ps=4*S; printf("The Perimeter of a Square with side %f is %f",S,Ps); system("Pause"); break; case 2: //Area of A Square system("cls"); printf("This computes the perimeter of a Square"); printf("\n\n"); printf("Enter Length of Side"); scanf("%f",&S); As= S*S; printf("The Area of a Square with side %f is %f",S,As); system("Pause"); break; case 3: //Volume of A Cube system("cls"); printf("This computes the volume of a Cube"); printf("\n\n"); printf("Enter Length of Side"); scanf("%f",&S); Vs= (S*S*S); printf("The volume of a cube with side %f is %f", S,Vs); system("Pause"); break; case 4: //exit from chs return main(); default: printf("The Operation cannot be done"); break; } }while(chs!=4); case 3: //triangle do{ system("cls"); printf("Triangle"); printf("\n1. Perimeter"); printf("\n2. Area"); printf("\n3. Volume"); printf("\n4. Exit"); printf("\n \n"); printf("\nChoice: "); scanf("%d", &cht); switch(cht){ case 1: //Perimeter of a Triangle system("cls"); printf("This computes the Perimeter of a Triangle"); printf("\n\n"); printf("Enter Length of Side"); scanf("%f",S); Pt= S+S+S; printf("The Perimeter of a triangle with side %f is %f",S,Pt); system("Pause"); break; break; case 2: // Area of a Triangle system("cls"); printf("This computes the Area of a triangle"); printf("\n\n"); printf("Enter Base"); scanf("%f",&b); printf("Enter Height"); scanf("%f",&h); At= ((b*h)/2); printf("The Area of a Triangle with Base %f and Height %f is %f",b,h,At); system("Pause"); break; break; case 3: // Volume system("cls"); printf("This computes the volume of a pyramid"); printf("\n\n"); printf("Enter Area of the base of the Pyramid"); scanf("%f",b); printf("Enter Height of the Pyramid"); scanf("%f",h); Vt= b*h; printf("The Volume of the pyramid with Base Area of %f and Heigh of %f is %f",b,h,Vt); system("Pause"); break; break; case 4: //exit from cht return main(); default: printf("The Operation cannot be done"); } case 4: //exit from ch }while(ch!=4); system("PAUSE"); return 0; }
any opening { requires a closing }.

at a glance: after line 69 there's a } missing.
@coder777
thanks! found everything and solved it :)
Hi Justin,

If you have compiler errors, then please post them in full. They have line numbers which makes it easier for us to see what is happening.

First thing I notice is that you need to make more use of functions. Each menu should be displayed with a function. Have a switch for the main menu, but have each case call a function. This will tidy up your code quite a bit. AND will probably get rid of the calls to main() you have - line 66 for example. NEVER CALL MAIN - it leads to a stack overflow.

Next, if you are going to use scanf, make sure that it worked. Not doing so is often a recipe for disaster, because you can easily have a garbage value. scanf returns a value which indicates how many values were successfully read - make use of this.

The other thing is to use meaningful names for your variables, it aids greatly in understanding what is going on.

Rather than a #define statement for pi, prefer to use a constant double instead. Depending on which implementation you have, M_PI might already have a value in the math header. Rather annoyingly IMO, this is not standard, so it might be best to stick with you own const assignment.

The end conditions in your do loops aren't right - I prefer to do something like this instead:

 http://www.cplusplus.com/forum/beginner/99203/#msg534078

Hope all is well

Topic archived. No new replies allowed.