Original assignment: "A user should be able to enter up to 200 items of float data. The program should calculate the number of items in the data. The symbol <EOF> in the sample run below should be replaced with CTRL-Z or CTRL-D or the end-of-file symbol on your system."
Example:
Item #1 : 25
Item #2 : 36
Item #3 : 27.5
Item #4 : 28
Item #5 : 32
Item #6 : 33.25
Item #7 : <EOF>
I'm having trouble implementing the CTRL-Z in my program, any ideas?
Code:
/*
My name is Jack Trocinski
*/
#include <stdio.h>
#include <stdlib.h>
int main()
{
float array[200]; // array of type float with 200 elements
int i; // used in for loop
for ( i = 0; i < 200; ++i) {
printf("Please input your data and press enter, use CTRL-Z to when you're done: ");
scanf("%f", &array[i]);
if (array[i] = EOF) break;
}
--i;
printf("The number items you have entered is: %d", i);
system("pause");
return 0;
}