Im trying to finish this homework assignment by tommarow afternoon and I keep getting stuck.
Write a Function that reads integers from the keyboard. If any are negative, it returns a negative. If all are positive, it returns an average of the numbers.
#include <stdio.h>
#include <stdbool.h>
/* Prototype Declarations */
bool anyPositiveEOF (void);
float readAverage (void);
int main (void)
{
/* Statements */
if (anyPositiveEOF())
printf("\nAll numbers are positive\n");
if (readAverage())
printf("\nAverage: %f\n", readAverage());
else
printf("\nAll numbers negative\n");
getch();
return 0;
} /* main */
bool anyPositiveEOF (void)
{
// Local Declarations
bool anyPositive = false;
int numIn;
// Statements
printf("Determine if any number are positive\n");
printf("Please enter any integers: \n");
while (scanf("%d", &numIn) != EOF)
{
anyPositive = numIn > 0;
if (anyPositive)
continue;
printf("next number: \n");
} // while
returnfalse;
}
float readAverage (void)
{
// Local Declarations
bool breakFlag = true;
int x = 0;
int y = 0;
int z = 0;
int count = 0;
int n;
float sum = 0;
while(scanf("%d",&n) != EOF)
{
if (n != 0)
{
sum += n;
count++;
} // if
} // while
return (sum / count);
}