我写这提示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