heyho
i read some about a challenge in C and coded it in a matter of minutes.
the exercise was:
Write a complete program that will ask for a person's name and his or her game score. Then it will ask for a second person's score. The program will print the winner's name and also print by how many points that person won.
heres my code
Code:
#include <stdio.h>
int main()
{
struct data
{
char name[256];
int score;
} names[2];
printf("enter the first name: ");
fgets(names[1].name, sizeof(names[1].name), stdin);
printf("enter the first score: ");
scanf("%d", &names[1].score);
printf("enter the second name: ");
fgets(names[2].name, sizeof(names[2].name), stdin);
printf("enter the second score: ");
scanf("%d", &names[2].score);
if(names[1].score < names[2].score)
{
printf("the winner is: ");
printf("%s\n", names[2].name);
printf("he won by %d points", names[2].score-names[1].score);
}
else
{
printf("the winner is: ");
printf("%s\n", names[1].name);
printf("he won by %d points", names[1].score-names[2].score);
}
return 0;
}
why is the second fgets/scanf statement ignored by my program?
whaa