Here is my entire code: This is not for any homework or anything, just messing around but can't spot this problem.
Code:
#include <stdio.h>
void displayMenu();
void fillArray(float array[], int n, int i);
//float computeMean(arguments here);
//float computeStandardDeviation(arguments here);
//float computeMode(arguments here);
//float computeRange(arguments here);
void restartProgram(char);
int main()
{
int n = 0;
int i = 0;
int input = 0;
int const MAX_DATA = 20;
int invalid = 1;
int temp = 1;
char var;
do
{
do
{
printf("Please give a number of inputs: ");
scanf("%d", &n);
if(n > 0 && n <= MAX_DATA)
{
invalid = 0;
}
else
{
printf("\nThat was a wrong choice. Please try again.\n\n");
}
}
while(invalid);
invalid = 1;
float data[n];
fillArray(data, n, i);
//displayMenu();
//do
//{
displayMenu();
do
{
printf("Please choose an operation: ");
scanf("%d", &input);
if(input > 0 && input < 6)
{
invalid = 0;
}
else
{
printf("\nThat was a wrong choice. Please try again.\n\n");
}
}while(invalid);
invalid = 1;
switch(input)
{
case 1:
//computeMean(arguments here);
//Print Here
break;
case 2:
//computeStandardDeviation(arguments here);
//Print Here
break;
case 3:
//computeMode(arguments here);
//Print Here
break;
case 4:
//computeRange(arguments here);
//Print Here
break;
case 5:
restartProgram(var);
break;
}
}while(1);
system("pause");
return 0;
}
void displayMenu()
{
printf("Statistical Calculator Menu:\n\n");
printf("(1) Mean\n");
printf("(2) Standard Deviation\n");
printf("(3) Mode\n");
printf("(4) Range\n");
printf("(5) Restart / Exit\n");
}
void fillArray(float data[], int n, int i)
{
for(i = 0; i < n; i++)
{
printf("Please enter input %d: ", i + 1);
scanf("%f", &data[i]);
}
printf("\nThank you.\n\n");
}
//float computeMean(arguments here){}
//float computeStandardDeviation(arguments here){}
//float computeMode(arguments here){}
//float computeRange(arguments here){}
void restartProgram(char answer)
{
printf("Would you like to enter another data set (Y/N)?: ");
scanf("%s", &answer);
switch(answer)
{
case 'Y': case 'y':
printf("Restarting Program...");
break;
case 'N': case 'n':
printf("\nExiting Program...\n\n");
system("pause");
exit(0);
break;
}
}
Input I have been using is:
3
1
2
3
5
y
I get Restarting Program... and then "Program has stopped working."