The following program is supposed to let the user enter a sequence of numbers until the user enters 0. Then the program will stop. After that I want to print the array with the numbers that the user have entered.
But this isn't working well. And I guess it is because when I enter a number sequence and press enter (without even entering the terminating 0) the array is initialized to have all numbers as 0.
So is that why the program terminates after this?
The reason to initialize the array with zeros is because I later on need to calculate the sum of the numbers.
Code:#pragma warning(disable:4996) #include <stdio.h> #define SIZE 100 int main() { float numbers[SIZE] = { 0 }; int i = 0; do { printf("Enter a sequence of numbers: "); scanf("%f", &numbers[i]); getchar(); i++; } while (numbers[i] != 0); return 0; }