I have a litte problem with EOF. I need to write numbers in one line with spaces between them and sum them together. Scanf must be ended with one EOF (Ctrl+D) I have this little program
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char** argv){
double numbers=0, sum=0;
printf("Enter numbers: ");
while(scanf("%lf", &numbers) != EOF){
sum=sum+numbers;
}
printf("\n %.2lf", sum);
}
Problem with this program is that I need to press Ctrl+d two times until it prints sum.
Example input/output:
Enter numbers: 1 3 5 6 <'Ctrl+d'>
15.00
scanf
(and family) reference, for more information about what it returns. – Some programmer dudewhile(scanf("%lf", &numbers) == 1) {
– chux - Reinstate Monica