Heres the problem: Write a program that reads integers until 0 is entered. After input terminates, the program should report the total number of even integers (excluding the 0) entered, the average value of the even integers, the total number of odd integers entered, and the average value of the odd integers.
The program stalls at the input loop, and the odd and even integers aren't getting in the array. What am I doing wrong? Any help would be greatly appreciated.
heres my code so far
Code:
#include <stdio.h>
int main(void)
{
int index, num2, num[20], nume[20], numo[20];
int sum1, odd = 0;
int sum2, even = 0;
float ave1, ave2;
printf("Enter up to 20 integers:\n");
for (index = 0; num[index] != '0'; index++) //should read input until 0 is entered but doesn't
scanf("%d", &num[index]);
for (index = 0; num[index] != '0'; index++) // this set of nested loops is to find odd and
{ //even integers then putting them into seperate arrays
num2 = num[index];
for(;num2>1;num2-=2);
{
if(num2 == 1)
{
numo[index] = (num2 += 2); //to get the number back to its original value
odd++;
}
else
{
nume[index] = (num2 += 2); //to get the number back to its original value
even++;
}
}
}
for (index = 0; index <= odd; index++) //to find the sum of all the odd integers
sum1 += numo[index];
for (index = 0; index <= even; index++) //to find the sum of all the even integers
sum2 += nume[index];
ave1 = sum1 / odd; //to find the average of the even integers
ave2 = sum2 / even; //to find the average of the odd integers
printf("%d %s even, %d %s odd.\n", even, even == 1 ? "is" : "are", odd, odd == 1 ? "is" : "are");
printf("The average even number is %0.1f, the average odd number is %0.1f.\n", ave2, ave1);
system ("pause");
return 0;
}