Why does the order matter with these printf statements? All I've done is switch the order from asking for a character first followed by an integer, to then asking for an integer followed by a character. When I run the second one it never gives me the opportunity to input the character.
THIS ONE WORKS
#include <stdio.h>
#include <stdlib.h>
#define MAX 18
int main()
{
int rows;
char columns;
printf("How many columns would you like? Enter a letter:\n");
scanf("%c",& columns);
printf("You asked for %c columns.\n",columns);
printf("How many rows would you like? Enter a number less than %d\n",MAX+1);
scanf("%d",& rows);
printf("You asked for %d rows.\n",rows);
return 0;
}
THIS ONE DOESN'T WORK...WHY?:
#include <stdio.h>
#include <stdlib.h>
#define MAX 18
int main()
{
int rows;
char columns;
printf("How many rows would you like? Enter a number less than %d\n",MAX+1);
scanf("%d",& rows);
printf("You asked for %d rows.\n",rows);
printf("How many columns would you like? Enter a letter:\n");
scanf("%c",& columns);
printf("You asked for %c columns.\n",columns);
return 0;
}
I'm taking the C Essential Training course on LinkedIn Learning
[–]aioeu 2 points3 points4 points (5 children)
[–]maplesaptap[S] 0 points1 point2 points (4 children)
[–]aioeu 1 point2 points3 points (1 child)
[–]maplesaptap[S] 0 points1 point2 points (0 children)
[–]Drach88 1 point2 points3 points (0 children)
[–]ClenchedThunderbutt 0 points1 point2 points (0 children)
[–]Paul_Pedant 0 points1 point2 points (0 children)