Hello
I excuse my bad english.
I am trying to make a program which manages the data of 5 different patients (its an uni assignment), and i want to use a switch case as a menu to switch between the patients. All other functions (as for example putting the infromation on a file) work, but i cant figure out to bring the switch to work. First it asks for the number of the patient which should be worked with, this works perfectly, but afterwards changiung between the persons doesnt work as thought. It should ask everytime after it switches to one patient (i removed some functions to make it easier to read) and then asks to which it should jump next. If i put the number of one case (lets say 3) it just stops the program.
********Example:
user@pc ~/wherever $ ./program
current variables:
jo = 2
a = 0
1 //the entered number
The variable a = 1
patient 1
Enter the number of the next patient2
// and then it closes
**************
The same thing happens if i compile an example code from a book, it writes the first case and then stops.
I looked already through the forum but didnt find a person with a similar problem, maybe i didnt dig deep enough.
I am running Linux Mint 17 and use gcc as compiler.
Code:
include <stdio.h>
#include <stdlib.h>
int a=0;
int jo=2;
int main(void){
printf("current variables:\n jo = %d\n a = %d\n", jo, a);
scanf("%d", &a);
printf("The variable a = %d\n", a);
switch ( a ) {
case 1:
printf("patient 1 \n");
ChooseA();
break;
case 2:
printf("patient 2 \n");
ChooseA();
break;
case 3:
printf("patient 3 \n");
ChooseA();
break;
case 4:
printf("patient 4 \n");
ChooseA();
break;
case 5:
printf("patient 5 \n");
ChooseA();
break;
case 6:
printf("Do you want to delete the collected data? 1 for yes/0 for no \n");
jo=2;
scanf("%d", &jo);
if(jo == 1){
FILE *fp;
fp=fopen("/home/jpreissler/Skrivebord/ImperativProgrammering/database.txt", "w");
fclose(fp);
printf("Data deleted\n");
}
if(jo == 0){
printf("No data deleted\n");
}
else{
}
break;
default:
printf("NUMBER NOT VALID\n");
}
return(0);
}
int ChooseA(){
printf("Enter the number of the next patient");
scanf("%d", &a);
}