コードに問題があります。私のプログラムは登録システムで、スイッチケースを選択するたびに合計金額が表示されるはずですが、登録する最後の科目を選択した後、合計金額の追加が間違っているようです。助けてください。
#include <stdio.h>
#include <stdlib.h>
int main()
{
int n, none, ntwo, nthree, Total;
float Algebra, Trigonometry, Calculus, Engiana, Physics;
char password[20], username[8];
Algebra = 100;
Trigonometry = 300;
Calculus = 500;
Engiana = 750;
Physics = 1500;
Total = (none + ntwo + nthree);
printf("Welcome to the Enrollment System \n");
printf("Here is the list of Available Subjects \n");
printf("\n");
printf("Course Code Price\n");
printf("\n");
printf("1. Algebra %.2f \n",Algebra);
printf("2. Trigonometry %.2f \n",Trigonometry);
printf("3. Calculus %.2f \n",Calculus);
printf("4. Engiana %.2f \n",Engiana);
printf("5. Physics %.2f \n",Physics);
printf("You can only select three courses to enroll for the Term \n");
printf("\n Select First Course to Enroll \n");
scanf("%d", &none);
switch(none)
{
case 1: printf(" You Enrolled Algebra %.2f \n",Algebra); break; //if conditions met , immediately goes to system pause
case 2: printf(" You Enrolled Trigonometry %.2f \n", Trigonometry); break; //if conditions not met goes to another case
case 3: printf(" You Enrolled Calculus %.2f \n", Calculus); break;
case 4: printf(" You Enrolled Engiana %.2f \n", Engiana); break;
case 5: printf(" You Enrolled Physics %.2f \n", Physics); break;
default: printf(" The Course you entered is not valid \n"); break;
}
printf("\n Select Second Course to Enroll \n");
scanf("%d", &ntwo);
switch(ntwo)
{
case 1: printf(" You Enrolled Algebra %.2f \n",Algebra); break; //if conditions met , immediately goes to system pause
case 2: printf(" You Enrolled Trigonometry %.2f\n", Trigonometry); break; //if conditions not met goes to another case
case 3: printf(" You Enrolled Calculus %.2f\n", Calculus); break;
case 4: printf(" You Enrolled Engiana %.2f\n", Engiana); break;
case 5: printf(" You Enrolled Physics %.2f \n", Physics); break;
default: printf(" The Course you entered is not valid \n"); break;
}
printf("\n Select Third Course to Enroll \n");
scanf("%d", &nthree);
switch(nthree)
{
case 1: printf(" You Enrolled Algebra %.2f \n",Algebra); break; //if conditions met , immediately goes to system pause
case 2: printf(" You Enrolled Trigonometry %.2f \n", Trigonometry); break; //if conditions not met goes to another case
case 3: printf(" You Enrolled Calculus %.2f \n", Calculus); break;
case 4: printf(" You Enrolled Engiana %.2f \n", Engiana); break;
case 5: printf(" You Enrolled Physics %.2f \n", Physics); break;
default: printf(" The Course you entered is not valid \n"); break;
}
printf("Total Tuition Price = %.2f \n",Total);
system("PAUSE");
return 0;
}