# How do I go back to my Menu after every switch and how to error trap effectively?

+1 vote
Here's a part of our program.

#include <stdio.h>

#include <stdlib.h>

int main()

{

int i, input,  AvoCal, IdealCal, ComCal;

double n, P, V, T, V1, V2, n1, n2, P1, P2, T1, T2;

const float R=0.0821;

while(1)

{

printf("\n\nGas Laws Calculator\n\n");

printf("(2) Ideal Gas Law\n");

printf("(3) Combined Gas Law\n");

printf("(4) Quit\n");

scanf("%d",&input);

break;

}

// Solutions

switch(input)

{case 1:

printf("Please select what you want to calculate.\n");

printf("\n(1) Find Volume (V1)\n");

printf("(2) Find Volume (V2)\n");

printf("(3) Find Moles (n1)\n");

printf("(4) Find Moles (n2)\n");

printf("(5) Quit\n");

scanf("%d",&AvoCal);

if (AvoCal==1)

{

printf("\nFind V1\n");

printf("Enter given values.\n");

printf("Value of V2: ");

scanf("%lf", &V2);

printf("Value of n2: ");

scanf("%lf", &n2);

printf("Value of n1: ");

scanf("%lf", &n1);

V1=(n1*V2)/n2;

}

else if (AvoCal==2)

{

printf("\nFind V2\n");

printf("Enter given values.\n");

printf("Value of n2: ");

scanf("%lf", &n2);

printf("Value of V1: ");

scanf("%lf", &V1);

printf("Value of n1: ");

scanf("%lf", &n1);

V2=(n2*V1)/n1;

}

else if (AvoCal==3)

{

printf("\nFind n1\n");

printf("Enter given values.\n");

printf("Value of n2: ");

scanf("%lf", &n2);

printf("Value of V1: ");

scanf("%lf", &V1);

printf("Value of V2: ");

scanf("%lf", &V2);

n1=(n2*V1)/V2;

}

else if (AvoCal==4)

{

printf("\nFind n2\n");

printf("Enter given values.\n");

printf("Value of n1: ");

scanf("%lf", &n1);

printf("Value of V2: ");

scanf("%lf", &V2);

printf("Value of V1: ");

scanf("%lf", &V1);

n2=(n1*V2)/V1;

}

else if (AvoCal==5);

exit (0);