我寫這提示2號用戶一個特殊的計算器,然後顯示其basicly詢問用戶如何處理該輸入的菜單。它很好用,但無論輸入什麼數字,結果都是0.我做錯了什麼?這個C程序有什麼問題?
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <math.h>
int main()
{
char a, rad, patrat;
float x, y, media, radical, pat1, pat2;
patrat = 253;
rad = 251;
loop:
printf("Input 2 numbers...\n");
scanf("%f %f", &x, &y);
media = (x+y)/2;
radical = sqrt(x+y);
pat1 = x*x;
pat2 = y*y;
loop2:
printf("\n \nA - Arithmetic media.\n");
printf("B - Square root.\n");
printf("C - Sqare of the 2 numbers.\n");
printf("D - Write other numbers.\n");
printf("E - Terminate the program.\n");
a = getch();
switch(a) {
case'a':
system("cls");
printf("Media of the 2 numbers is %f", &media);
goto loop2;
case'b':
system("cls");
printf("%c%f + %f = %f", &rad, &x, &y, &radical);
goto loop2;
case'c':
system("cls");
printf("%f%c = %f, %f%c = %f", &x, &patrat, &pat1, &y, &patrat, &pat2);
goto loop2;
case'd':
goto loop;
case'e':
return 0;
}
}
您可能需要首先閱讀[文章](http://www.cs.utexas.edu/~EWD/transcriptions/EWD02xx/EWD215.html)和/或[這個問題(http://stackoverflow.com/questions/46586/goto-still-considered-harmful),並嘗試restructurate你的代碼;) – Kevin 2012-01-04 09:00:13
編輯:我會考慮它。 – Bugster 2012-01-04 09:00:58
哇!轉到 - 在一段時間內沒有看到其中的一個。 – Tom 2012-01-04 09:02:02