I have 4 arrays. 1 is a char array. The other 3 are int arrays. I want to perform data validation on them inside of my for loop. With the char array input validation, I want the user to go into a while loop until they enter an alphabetical value. And for the other 3 int arrays, I want the user to go into a while loop until they enter a numerical value. I tried to do this myself, but it is making me enter the values twice, meaning my while loop is running once and then moving forward. Can anyone see what I am doing wrong
#include <stdio.h>
#include <stdlib.h>
#define NUM_TEAM 10
void displayWelcome(void);
int main(void)
{
char teamName[NUM_TEAM + 1][30] = { "" };
int teamWins[NUM_TEAM] = {0};
int teamLosses[NUM_TEAM] = {0};
int teamTies[NUM_TEAM] = {0};
int i, bestPercent, worstPercent;
displayWelcome();
//Team Name
for (i = 0; i < NUM_TEAM; i++)
{
//Prompt and enter team name
fflush(stdin);
printf("\nEnter %i's team name: ", i + 1);
fgets (teamName[i], sizeof teamName[NUM_TEAM], stdin);
while ( 1 != scanf( "\n%c", &teamName )) //Data validation
{
fflush(stdin);
printf("Enter an alphabetical value: ");
}
//Team wins array prompt & input
printf("\nEnter wins for team number %i : ", i + 1);
scanf("%i", &teamWins[ i ]);
while ( 1 != scanf( "%i", &teamWins[ i ] ) || teamWins[ i ] <= 0) //Data validation
{
fflush(stdin);
printf("Enter a numerical value: ");
}
//Team losses array prompt & input
printf("\nEnter losses for team number %i : ", i + 1);
scanf("%i", &teamLosses[ i ]);
while ( 1 != scanf( "%i", &teamLosses[ i ] ) || teamLosses[ i ] <= 0)
//Data validation
{
fflush(stdin);
printf("Enter a numerical value: ");
}
//Team ties array prompt & input
printf("\nEnter ties for team number %i : ", i + 1);
scanf("%i", &teamTies[ i ]);
while ( 1 != scanf( "%i", &teamTies[ i ] ) || teamTies[ i ] <= 0)
//Data validation
{
fflush(stdin);
printf("Enter a numerical value: ");
}
}
//Display Data
for (i = 0; i < NUM_TEAM; i++)/* output each word read */
{
printf("%s", teamName[i]);
printf("wins losses ties\n");
printf("%i %i %i\n", teamWins[i], teamLosses[i], teamTies[i]);
}
return 0;
}
void displayWelcome(void)
{
printf("Welcome to my Football Stats\n");
}