This can be easily done with a loop:
int main()
{
bool exit=false;
while (!exit)
{
//CODE HERE!
//somewhere have:
/* if (user_want_to_quit)
exit=true;
*/
}
return 0;
}
Labdabeta
Practically a Master Poster
615 posts since Feb 2011
Reputation Points: 27
Solved Threads: 31
Skill Endorsements: 1
The thing is that you cannot (as far as I know) call main recursively (from within itself) and even if you can it is likely a bad idea (if the user wants to do 100 problems you will outrun your stack) The key is to use a loop. Here is an example for your code:
#include <stdio.h>
#include <conio.h>
main()
{
float choice,A,CUBE;
char temp;
bool exit=false;
while (!exit)//loop until we want to exit
{//I do not know why you put a block here... but I am using it :P
clrscr();
textcolor(BLUE);
gotoxy (24,5);
cprintf("SOLVE FOR THE FOLLOWING VOLUMES\n");
textcolor(345);
gotoxy (26,7);
cprintf("[1] - CUBE");
gotoxy (26,8);
cprintf("[2] - CONE");
gotoxy (26,9);
cprintf("[3] - SPHERE");
gotoxy (26,10);
cprintf("[4] - CYLINDER");
gotoxy (26,11);
cprintf("[5] - EXIT");
textcolor(RED);
gotoxy (24,14);
cprintf("Enter your choice: ");
scanf("%f",&choice);
switch(choice)
{
case 1:
{
clrscr();
textcolor (BLUE);
gotoxy (30,5);
cprintf("Volume of CUBE");
textcolor (345);
gotoxy (24,7);
cprintf("Enter the side of the cube: ");
scanf("%f",&A);
CUBE= (A*A*A);
scanf("%2.0f,&CUBE");
textcolor (345);
gotoxy (24,10);
cprintf("The Volume of the CUBE is %2.0f", CUBE);
}
case 5://you do not NEED blocks after a case statement, but they can make your code look nicer
textcolor (RED);
gotoxy(24,14);
cprintf("Would you like to compute again(Y/N)? ");
scanf("%c", &temp);
exit = (!(temp == 'y' || temp == 'Y'));//set the exit variable
}//end switch
}//end while
return 0;
}//indentation would have told you that this bracket ends main
Labdabeta
Practically a Master Poster
615 posts since Feb 2011
Reputation Points: 27
Solved Threads: 31
Skill Endorsements: 1