hi guys im jus wondering wat i can do to get my menu to work. What happens atm is ill enter an option, get the correct output then it will tell me to press any key to continue. At this point it goes back to the menu but jus says "press any key to continue" and then it closes. Code below:
Code:
#include <stdio.h>
#include <stdlib.h>
#define txt "critpathinfo.txt"
int main()
{
char choice;
int a, b, c;
printf(" Welcome to Critical Path Analysis \n");
printf("_____________________________________________________________\n");
printf(" a --- print event number, maximum number of days for a task,\n total number of days for the project completion.\n");
printf("\n b --- print the event number and task number for all tasks\n requiring more than 5 days.\n");
printf("\n c --- print the number of each event, a count of number of tasks\n within the even.\n");
printf("\n q --- quit the program\n");
printf("_____________________________________________________________\n");
printf(" Please make your choice: ");
scanf("%c",&choice);
if(choice=='a')
{
a= func_a();
}
if(choice=='b')
{
b= func_b();
}
if(choice=='c')
{
c=func_c();
}
}
int func_a()
{
int e, t, d;
int event=1;
int numdays=0;
int totald=0;
FILE* data;
data= fopen(txt,"r");
if(data==NULL)
printf("Error opening input file \n");
else
{
while(fscanf(data,"%d%d%d",&e,&t,&d)==3)
{
if(event==e)
{
if(d>numdays)
numdays=d;
}
else
{
totald=totald + numdays;
printf("\n%d %d",event,numdays);
event=e;
numdays=d;
}
}
printf("\n%d %d",event,numdays);
totald=totald+numdays;
printf("\nTotal days to complete the project: %d\n",totald);
}
fclose(data);
system("PAUSE");
return main();
}
int func_b()
{
int e, t, d;
FILE* data;
data= fopen(txt,"r");
if(data==NULL)
printf("Error opening input file \n");
else
{
while(fscanf(data,"%d%d%d",&e,&t,&d)==3)
if(d>5)
printf("\n%d %d",e,t);
}
fclose(data);
system("PAUSE");
return main();
}
int func_c()
{
int e, t, d;
int event=1;
int numtasks=0;
FILE* data;
data= fopen(txt,"r");
if(data==NULL)
printf("Error opening input file \n");
else
{
while(fscanf(data,"%d%d%d",&e,&t,&d)==3)
{
if(event==e)
{ ++numtasks;
event=e;
}
else
{ printf("\n%d %d",event,numtasks);
numtasks=1;
event=e;
}
}
printf("\n%d %d",event,numtasks);
}
fclose(data);
system("PAUSE");
return main();
}