そのため、今回も新しいプログラミング言語を学習しています。これはCです。メインメニュー用にこの関数を作成した後、宣言されたdouble "equiv"は、同等の略で、割り当てられた同等のものを正しく出力しないようです。バグが発生している部分にコメントしました。
関数のコードは次のとおりです。
// function for grading system
void gradeSys()
{
char response;
// declaration for computing midterm grades
double Mquiz1 = 0, Mquiz2 = 0, Mquiz3 = 0, Mrecit = 0, Massign = 0, MAve = 0, Midex = 0;
// declaration for computing final grades
double Fquiz1 = 0, Fquiz2 = 0, Fquiz3 = 0, Frecit = 0, Fassign = 0, FAve = 0, Finex = 0;
char answer;
int counter = 1;
// while loop
while(counter != 0) {
/*!!!---Midterm Grades Input---!!!*/
printf("Welcome to your Grading System.\n");
printf("Please enter your grades for Midterm:\n");
printf("M. Quiz1:\n");
scanf("%d" , &Mquiz1);
printf("M. Quiz2:\n");
scanf("%d" , &Mquiz2);
printf("M. Quiz3:\n");
scanf("%d" , &Mquiz3);
printf("M. Recitation\n");
scanf("%d" , &Mrecit);
printf("M. Assignment\n");
scanf("%d" , &Massign);
printf("M. Exam:\n");
scanf("%d" , &Midex);
// formula for computing midterm grades
double Midgrade = 0;
MAve = (Mquiz1 + Mquiz2 + Mquiz3 + Mrecit + Massign)/5;
double MAveTotal = MAve * .60;
double MidExAve = Midex * .40;
Midgrade = MAveTotal + MidExAve;
printf("Your Midterm average is: %d\n", MAve);
printf("Your Midterm Grade is: %d\n", Midgrade);
printf("Please press enter to continue...\n");
getchar();
getchar();
system("cls");
/*!!!---Final Grades Input---!!!*/
printf("Please enter your grades for Finals:\n");
printf("F. Quiz1:\n");
scanf("%d" , &Fquiz1);
printf("F. Quiz2:\n");
scanf("%d" , &Fquiz2);
printf("F. Quiz3:\n");
scanf("%d" , &Fquiz3);
printf("F. Recitation\n");
scanf("%d" , &Frecit);
printf("F. Assignment\n");
scanf("%d" , &Fassign);
printf("F. Exam:\n");
scanf("%d" , &Finex);
// formula for computing final grades
double Fingrade = 0;
FAve = (Fquiz1 + Fquiz2 + Fquiz3 + Frecit + Fassign)/5;
double FAveTotal = FAve * .60;
double FinExAve = Finex * .40;
Fingrade = FAveTotal + FinExAve;
printf("Your Final average is: %d\n", FAve);
printf("Your Final Grade is: %d\n", Fingrade);
printf("Please press enter to continue...\n");
getchar();
getchar();
/*!!!--- Here is where the bug occurs ---!!!*/
// declaration and formula for the term grade
double termGrade = 0, equiv;
termGrade = (Midgrade + Fingrade)/2;
// decision formula for determining equivalent
if(termGrade >= 90 && termGrade <= 100)
{
equiv = 4.0;
}
else if(termGrade >= 85 && termGrade <= 89)
{
equiv = 3.0;
}
else if(termGrade >= 75 && termGrade <= 84)
{
equiv = 2.0;
}
else if(termGrade >= 70 && termGrade <= 74)
{
equiv = 1.0;
}
else if(termGrade >= 00 && termGrade <= 69)
{
equiv = 0.0;
}
else
{
printf("Invalid grade. Try again.\n");
}
// displays the ovarall grade for the term and the equivalent
printf("Your grade for this term is: %d. Which is equivalent to a: %d.\n", termGrade, equiv);
getchar();
system("cls");
// try again?
printf("Do you want to try again:[Y/N]\n");
scanf("%c", &answer);
if(answer == 'y' || answer == 'Y')
{
system("cls");
continue;
}
else if(answer == 'n' || answer == 'N')
{
system("cls");
counter = 0;
}
else
{
printf("Invalid input\n");
}
}
}