This question already has an answer here:
I'm trying to get 5 float values from the user using scanf, the problem is the user is required to input 6 values for the program to complete. Although I know I shouldn't use scanf, it bothers me that there's something I can't grasp about it. Any insights, any advice on how to fix it whilst using scanf?
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i = 0 , j = 0;
char buf[128] = {0};
float numbers[5] = {0.0};
float keep = 0.0;
printf("Please input 5 numbers : \n");
for (i = 0; i < 5; i++)
{
scanf("%f\n", &numbers[i]);
}
printf("Done!");
Thanks,
MIIJ
you must remove \n in scanf() function
scanf("%f\n", &numbers[i]);
should bescanf("%f", &numbers[i]);