我遇到了我的代碼問題。我的課程是一個招生系統,每次我選擇一個開關盒時,它應該顯示總價格,但在選擇最後一門課程後,總價格增加看起來是錯誤的。請幫忙。加法和賦值錯誤
#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;
}
'代數''等是'int'(因爲它們沒有類型),但你似乎把它們當作float('「...%.2f \ n」,代數「')? – trojanfoe
@trojanfoe它們是'float',line #2功能 –
@KarthikT糟糕 - 錯過了... – trojanfoe