c - 这个C程序有什么问题?

标签 c

我编写了一个特殊的计算器,提示用户输入 2 个数字,然后显示一个菜单,该菜单基本上询问用户如何处理该输入。它工作得很好,但是无论我输入什么数字,结果都是 0。我做错了什么?

#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;
    }
    }

最佳答案

您不应该在 printf 语句中使用 &。 Scanf 在编写时拥有它,因此需要指点。

关于c - 这个C程序有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8724219/

相关文章:

c - 在 C 中使用排序/qsort

c - 如何找到stack smash的原因

python - PyList_New 导致 SEGFAULT

c++ - C 或 C++ 中是否有 "inverted"trunc 函数?

c - C中的文件内存泄漏

c - 对于通用内存池,如何在 C 中的指针之间自由转换?

c - C 中的可变大小矩阵

c - C语言中如何处理小数点后10位以上的INT?

c - 传递结构以在 C 中用作参数

c - 有多少种方法可以打印我们的整数数组?