Is there a way to prompt a user for a number, but if the user enters a character such as a letter, to just skip that entry? If it helps, here is the code I have so far:
Code:
#include <stdio.h>
#include <math.h>
#define Max_numbers 10
int main(void)
{
double x[Max_numbers];
int i;
char str[20];
printf( "Please enter your name:\t " );
gets(str);
printf("Hello, %s!\n", str);
printf("Please Enter %d numbers separated by spaces or returns\n",
Max_numbers);
for (i = 0; i < Max_numbers; ++i) {
scanf("%lf", &x[i]);
if (x[i] == 0)
i +=10; }
system("Pause");
}
I have it so the program will stop retrieving numbers if the user enters "0". Is an array the best way to do this? Thanks in advance!