To write a c program to maintain a log of football match b/w 2 teams and then compare the results of the log entered by user and announce the winner.
-
Tarun Jha wrote:
Enter the number of logs: 5 Enter log-1
And there is your code:
for(i=0; i
So why do you think the loop skips when i is zero??? It works and prints the result
"Enter log-1" -
are you suggesting that i initialize input to zero before applying gets() as you told me to do in the previous question answered by you.
-
No, I am telling you to go and get a proper study guide and learn the C language in complete detail.
-
No, I am telling you to go and get a proper study guide and learn the C language in complete detail.
-
i will but befoer that can you show me how to correct the buffering problem of scanf() in order to remove newline charecter from gets().
-
And here is the working code :)
#include
#includeint main()
{
int i, log, j, c1=0, c2=0;
char team_1[100], team_2[100], input[100], ch;printf("Enter name of Team-1: \\n"); gets(team\_1); printf("Enter the name of Team-2\\n"); gets(team\_2); if(strcmp(team\_1, team\_2)==0) { printf("Oops! both names are same. Please enter again: \\n"); while(strcmp(team\_1, team\_2)==0) { printf("Enter name of Team-1: \\n"); gets(team\_1); printf("Enter the name of Team-2\\n"); gets(team\_2); } } printf("Enter the number of logs: \\n"); scanf("%d%\*c", &log); for(i=0; ic2) printf("\\nTeam-1 wins"); else if(c1
-
here is the code i have wrriten but when reaching the for()loop it just skips though the first loop of for( i.e. i=0 )and starts with i=1. What is wrong in the code.
#include
#includeint main()
{
int i, log, k, c1=0, c2=0, j=0;
char team_1[100], team_2[100], input[100], ch;printf("Enter name of Team-1: \\n"); gets(team\_1); printf("Enter the name of Team-2\\n"); gets(team\_2); if(strcmp(team\_1, team\_2)==0) { printf("Oops! both names are same. Please enter again: \\n"); while(strcmp(team\_1, team\_2)==0) { printf("Enter name of Team-1: \\n"); gets(team\_1); printf("Enter the name of Team-2\\n"); gets(team\_2); } } printf("Enter the number of logs: \\n\\n"); scanf("%d", &log); for(i=0; ic2) printf("Team-1 wins"); else printf("Team-2 wins"); return 0;
}
And here is the working code..
#include
#includeint main()
{
int i, log, j, c1=0, c2=0;
char team_1[100], team_2[100], input[100], ch;printf("Enter name of Team-1: \\n"); gets(team\_1); printf("Enter the name of Team-2\\n"); gets(team\_2); if(strcmp(team\_1, team\_2)==0) { printf("Oops! both names are same. Please enter again: \\n"); while(strcmp(team\_1, team\_2)==0) { printf("Enter name of Team-1: \\n"); gets(team\_1); printf("Enter the name of Team-2\\n"); gets(team\_2); } } printf("Enter the number of logs: \\n"); scanf("%d%\*c", &log); for(i=0; ic2) printf("\\nTeam-1 wins"); else if(c1
-
here is the code i have wrriten but when reaching the for()loop it just skips though the first loop of for( i.e. i=0 )and starts with i=1. What is wrong in the code.
#include
#includeint main()
{
int i, log, k, c1=0, c2=0, j=0;
char team_1[100], team_2[100], input[100], ch;printf("Enter name of Team-1: \\n"); gets(team\_1); printf("Enter the name of Team-2\\n"); gets(team\_2); if(strcmp(team\_1, team\_2)==0) { printf("Oops! both names are same. Please enter again: \\n"); while(strcmp(team\_1, team\_2)==0) { printf("Enter name of Team-1: \\n"); gets(team\_1); printf("Enter the name of Team-2\\n"); gets(team\_2); } } printf("Enter the number of logs: \\n\\n"); scanf("%d", &log); for(i=0; ic2) printf("Team-1 wins"); else printf("Team-2 wins"); return 0;
}
You have identified "problem area " , so work on problem area first. No matter how many books you read , they will NEVER tell you that MAJORITY of errors are typos, and than you will have hidden SYNTAX errors. The last errors are programming - LOGICAL errors. Before you compare real INPUTS, you have to have correct program sequence working so emulating the actual inputs would be next step. You are starting Backward with analysis of logical / real input errors. PS You have a "numerical" application , so prefacing printed numbers with "minus" sign" seems little odd. for(i=0; i
-
You have identified "problem area " , so work on problem area first. No matter how many books you read , they will NEVER tell you that MAJORITY of errors are typos, and than you will have hidden SYNTAX errors. The last errors are programming - LOGICAL errors. Before you compare real INPUTS, you have to have correct program sequence working so emulating the actual inputs would be next step. You are starting Backward with analysis of logical / real input errors. PS You have a "numerical" application , so prefacing printed numbers with "minus" sign" seems little odd. for(i=0; i
Dear Vaclav_, could you edit your post to properly format the code snippet? Otherwise it is very hard to read/understand.
-
You have identified "problem area " , so work on problem area first. No matter how many books you read , they will NEVER tell you that MAJORITY of errors are typos, and than you will have hidden SYNTAX errors. The last errors are programming - LOGICAL errors. Before you compare real INPUTS, you have to have correct program sequence working so emulating the actual inputs would be next step. You are starting Backward with analysis of logical / real input errors. PS You have a "numerical" application , so prefacing printed numbers with "minus" sign" seems little odd. for(i=0; i
it works too..
#include
#include
#includeint main()
{
int log, i, j, k, count1=1, count2=0, c;printf("Enter the number of logs: \\n"); scanf("%d%\*c", &log); char names\[log\]\[100\]; //Entering names. printf("Enter names: \\n"); gets(names\[0\]); //completing in a single loop. for(i=1; icount2) { puts(names\[0\]); printf("Wins !"); } else if(count2>count1) { puts(names\[k\]); printf("Wins !"); } else if(count1==count2) { printf("It's a tie!!"); } break; } count1++; } return 0;
}