Ok, so this function is supposed to take results from a user and then give them an option to input more results or return to the main menu main() when they're done.
Everything works fine. the only problem is at the last scanf
statement before the switch.
Instead of waiting for the users input in userChoice
, its automatically starting the function over again. Its only supposed to do that if userChoice
is 'a' or 'A' but it just completely ignores the scanf statement and the switch as well, it seems. What am i doing wrong? Scroll down to see the line im referring to.
void inputResults(int gameNumber, int i, int j)
{
int Results[ROWS][COLS];
char userChoice = ' ';
if (j >= COLS)
{
j = 0;
i = i + 1;
}
if (gameNumber > ROWS)
{
printf("\nJk, Max number of games reached\n");
main();
}
gameNumber = gameNumber + 1;
printf("\nHow many points did the home team score in game %d?\n", gameNumber);
scanf_s("%d", &Results[i][j]);
j = j + 1;
printf("\nHow many points did the opponents score in game %d?\n", gameNumber);
scanf_s("%d", &Results[i][j]);
printf("\nHome: %d Opponents: %d\n", Results[i][j-1], Results[i][j]);
printf("\nA) Enter results for game %d\nB) Main menu \n", (gameNumber + 1));
*************************PROBLEM***********************************
scanf_s("%c", &userChoice); /*it ignores THIS it just loops the
function after it prints the above*/
switch (userChoice) //it doesnt even get to this.
{
case 'A':
inputResults(gameNumber, i, j);
case 'a':
inputResults(gameNumber, i, j);
case 'b':
main();
case 'B':
main();
default:
printf("\nThats still not a valid choice dude\n");
}
}
the values passed into gameNumber, i, and j are all all 0 if you're wondering. They were passed from the main function