While I am also a beginner in programming, I think you might want to try using an "if" statement in your "for" loop.
this might be confusing, but I had to do something similiar...
Here is my version...you have to enter numbers (positve, negative, or zero) and count them...hope this helps..
good luck
#include <stdio.h>
#include <math.h>
int main ()
{ /*main*/
float*value=(float*)NULL;
const int minimum_number_of_values=1;
const int program_fail_code =1;
const int first_index=0;
const int program_success_code;
int number_of_values, index;
int number_of_zeros=0;
int number_of_positives=0;
int number_of_negatives=0;
printf("This is a trivial question, but this");
printf(" program counts postive, negative, and zero values.\n");
printf("How many values do you want to input?\n");
scanf("%d", &number_of_values);
if (number_of_values<minimum_number_of_values){
printf("ERROR! value not recognized.\n");
exit(program_fail_code);
} /* if (number_of_values<minimum_number_of_values) */
value=(float*)malloc(sizeof(float)*number_of_value s);
if(value==(float*)NULL){
printf("ERROR! Allocation failed.\n");
exit(program_fail_code);
} /* if(value==(float*)NULL) */
printf("Please enter %d values.\n", number_of_values);
for(index = first_index; index < number_of_values; index++){
scanf("%f", &value[index]);
} /* for(index=first_index; index<number_of_values, index++)*/
for(index = first_index; index < number_of_values; index++){
if (value[index] > 0){
number_of_positives++;
} /*if (value[index] > 0) */
} /* for(index=first_index; index<number_of_values, index++)*/
for(index = first_index; index < number_of_values; index++){
if(value[index] < 0){
number_of_negatives++;
} /* for(index=first_index; index<number_of_values, index++)*/
} /*(value[index] < 0) */
for(index = first_index; index < number_of_values; index++){
if(value[index] == 0){
number_of_zeros++;
} /* if(value[index] == 0) */
} /* for(index=first_index; index<number_of_values, index++)*/
printf("The number of positive numbers is %d.\n", number_of_positives);
printf("The number of negative numbers is %d.\n", number_of_negatives);
printf("The number of zeros is %d.\n", number_of_zeros);
free(value);
value = (float*)NULL;
return program_success_code;
} /* main */
