Hello guys! I have some trouble with that "Do you want to continue" thing in C. I am begginer. Well my problem is to fix this one:
.....
int sum_count_arithmeticaverage()
{
int n = 0;
char answer;
int array[1024];
int sum = 0, count = 0, arithmeticaverage;
int i = 0;
int z = 0;
do{
printf("Write element: ");
scanf_s("%d", &array[i]);
printf("Do you want to continue adding elements of the array? <Y/N> ");
scanf_s("%ch", &answer);
fflush(stdin);
array[n];
} while ((answer == 'y') || (answer == 'Y'));
for (i = 0; i < n; i++)
{
sum = sum + array[i];
count++;
arithmeticaverage = sum / n;
}
printf("| Sum=%d | Count=%d | Arithmetic average=%d |\n\n", sum, count, arithmeticaverage);
printf("->Even numbers in array are<-\n\n");
for (i = 0; i < n; i++)
{
if (array[i] % 2 == 0)
{
z = array[i];
printf("array[%d]=%d\n\n", i, z);
}
}
printf("->Odd numbers in array are<-\n\n");
for (i = 0; i < n; i++)
{
if (array[i] % 2 != 0)
{
z = array[i];
printf("array[%d]=%d\n\n", i, z);
}
}
return 0;
}
My idea is to make the array sum = "n" then the program to ask us do you want to continue, after we say "y" or "Y" to enter the next member of the array and so on... When we enter a word that is not "y" or "Y" the program stops.