I am self-learning C from the internet and I am currently on the if-else statement module.
I wrote this test program using the shorthand if else statement and it ran successfully:
int bodycount;
printf("How many people have you smiled at today ?: ");
scanf(" %d", &bodycount);
printf("you have smiled at %d %s ", bodycount, (bodycount != 1) ? "people today" : "person today");
However, I tweaked the program slightly to the underlying program:
int bodycount;
printf("How many people have you smiled at today?: ");
scanf(" %d", &bodycount);
printf("you have smiled at %d %s ", bodycount, (bodycount = 1) ? "person today" : "people today");
I noticed that it only responds correctly when bodycount = 1.
Why is this the case?
Aucun commentaire:
Enregistrer un commentaire