Hi, I just have a question for anyone who can help. I am trying to write a program that will print to a file. The program has a while loop so that when I run it, it should print to the file each time the loop cylces. It is only printing the 2nd to last cycle, which makes no sense to me. Everything else seem in order, here is my loop.
I'm sorry I know I'm supposed to put it in some special format to post here, but I dont know how to do that. Thanks for any help!
[code=c]
while(ID<999)
{
printf("\n\nEnt er 3 digit student ID or 999 to end input: ");
scanf("%d",&ID) ;
if (ID==999)
break;
printf("Enter Quiz 1 Score (out of 10): ");
scanf("%d", &quiz1);
printf("Enter Quiz 2 Score (out of 10): ");
scanf("%d",&qui z2);
printf("Enter Quiz 3 Score (out of 10): ");
scanf("%d", &quiz3);
printf("Enter Test 1 Score (out of 20): ");
scanf("%d",&tes t1);
printf("Enter Test 2 Score (out of 20): ");
scanf("%d",&tes t2);
printf("Enter Final Score (out of 30): ");
scanf("%d", &final);
total = quiz1+quiz2+qui z3+test1+test2+ final;
quiz = quiz1 + quiz2 + quiz3;
test = test1 + test2;
student=fopen(F ILENAME, "w");
fprintf(student ,"STUENT QUIZ MID_TERM FINAL GRADE\n");
if (total<55 && total>0)
t=0;
else
t= ((total-1)/10);
switch(t)
{
case 10: case 9:
{
printf("%d %5d %5d %5d \t A",ID, quiz, test, final);
fprintf(student ,"%d %5d %5d %5d \t A\n",ID, quiz, test, final);
}
break;
case 8:
{
printf("%d %5d %5d %5d \t B",ID, quiz, test, final);
fprintf(student ,"%d %5d %5d %5d \t B\n",ID, quiz, test, final);
}
break;
case 7: case 6: case 5:
{
printf("%d %5d %5d %5d \t C",ID, quiz, test, final);
fprintf(student ,"%d %5d %5d %5d \t C\n",ID, quiz, test, final);
}
break;
case 0:
{
printf("%d %5d %5d %5d \t F\n",ID, quiz, test, final);
fprintf(student ,"%d %5d %5d %5d \t F\n",ID, quiz, test, final);
}
break;
default:
printf("You have entered invalid information, please try again.");
}
fclose(student) ;[/code]
I'm sorry I know I'm supposed to put it in some special format to post here, but I dont know how to do that. Thanks for any help!
[code=c]
while(ID<999)
{
printf("\n\nEnt er 3 digit student ID or 999 to end input: ");
scanf("%d",&ID) ;
if (ID==999)
break;
printf("Enter Quiz 1 Score (out of 10): ");
scanf("%d", &quiz1);
printf("Enter Quiz 2 Score (out of 10): ");
scanf("%d",&qui z2);
printf("Enter Quiz 3 Score (out of 10): ");
scanf("%d", &quiz3);
printf("Enter Test 1 Score (out of 20): ");
scanf("%d",&tes t1);
printf("Enter Test 2 Score (out of 20): ");
scanf("%d",&tes t2);
printf("Enter Final Score (out of 30): ");
scanf("%d", &final);
total = quiz1+quiz2+qui z3+test1+test2+ final;
quiz = quiz1 + quiz2 + quiz3;
test = test1 + test2;
student=fopen(F ILENAME, "w");
fprintf(student ,"STUENT QUIZ MID_TERM FINAL GRADE\n");
if (total<55 && total>0)
t=0;
else
t= ((total-1)/10);
switch(t)
{
case 10: case 9:
{
printf("%d %5d %5d %5d \t A",ID, quiz, test, final);
fprintf(student ,"%d %5d %5d %5d \t A\n",ID, quiz, test, final);
}
break;
case 8:
{
printf("%d %5d %5d %5d \t B",ID, quiz, test, final);
fprintf(student ,"%d %5d %5d %5d \t B\n",ID, quiz, test, final);
}
break;
case 7: case 6: case 5:
{
printf("%d %5d %5d %5d \t C",ID, quiz, test, final);
fprintf(student ,"%d %5d %5d %5d \t C\n",ID, quiz, test, final);
}
break;
case 0:
{
printf("%d %5d %5d %5d \t F\n",ID, quiz, test, final);
fprintf(student ,"%d %5d %5d %5d \t F\n",ID, quiz, test, final);
}
break;
default:
printf("You have entered invalid information, please try again.");
}
fclose(student) ;[/code]
Comment