Part of my assignment is to write a function that takes 10 integers and if the user hits any other keyboard(letters) it goes back to main menu. The integers that the user entered should be available for other functions too(so I guess that I need to create a variable in main that keeps track of integers).
For example if the user decides to only enter 6 integers and then hit "c" the program should go back to main menu and know that there are 6 integers stored and next time user tries to enter more integers only allow 4 more.
I've been struggling for two days and I know the code is bad, but here it comes. My function for entering integers.
int enter(int a[], int n){
int i;
for( i=1; i<n;i++){
printf("Enter measurement #%d ", i);
if(scanf(" %d", &a[i]) == 1){
}
else{
printf("Exit!");
break;
}
} main();
}
My variables in main.
int nrOfMeasurements;
int measurements[10];
And my function in menu. If user hit "e", user can enter integers. This if statements is nested inside a while-loop.
if(ch == 'e'){
enter(measurements,10);
nrOfMeasurements = enter(measurements,nrOfMeasurements);
}