I'm new to the c language and used java before, so I'm not so familiar with some things... I want to read an indefinite number of integer until there's a new line. I know, that new line is ⁄n and I already have a code, so the integer are read until you type in a letter, but it doesn't stop, if there's a new line.
#include <stdio.h>
int main() {
int i, numberOfNumbs=0,total=0,value, valsRead;
float average;
valsRead = scanf("%d",&value);
while(valsRead>0)
{
numberOfNumbs++;
total +=value;
printf("Read %d\n", value);
valsRead = scanf("%d",&value);
}
average=(float)total/(float)numberOfNumbs;
printf("You read %d values. Average = %f.",numberOfNumbs, average);
return (0);
}
The input should be something like this: 23 4 114 2 34 3224 3 2 ⁄n
Thanks in advance