c - Switch case 程序没有给出输出

标签 c

#include<stdio.h>
int main()
{

int choice;
printf("Enter 1 for Programmers Name and ID\n");
printf("Enter 2 to Perform Integer Operation\n");
printf("Enter 3 to Perform Floating Point Operation\n");
scanf("%d", &choice);
system("CLS");

if (choice == 1)
    printf("Connor \n000000000\n");

else if (choice == 2)
{
    char c;
    int num1, num2;
    printf("Enter operator:");
    scanf("%c", &c);
    getchar();
    printf("Enter two integer's :");
    scanf("%d %d", &num1, &num2);

    switch (c)
    {
    case '+':
        printf("%d + %d = %d", num1, num2, num1 + num2);
        break;
    case '-':
        printf("%d - %d = %d", num1, num2, num1 - num2);
        break;
    case '*':
        printf("%d * %d = %d", num1, num2, num1*num2);
        break;
    case '/':
        printf("%d / %d = %d", num1, num2, num1 / num2);
        break;

    default:
        printf("The value of c = '%c'\n");
        system("pause");
        return(0);
    }
}
else if (choice == 3)
    printf("Enter two \n");


system("pause");
return(0);
}

我需要一点帮助来解决此代码的操作部分的一个小问题......一切正常,因为可以放入运算符和整数,但我没有从开关获得输出.

最佳答案

这肯定有效

    #include<stdio.h>
int main()
{

int choice;
printf("Enter 1 for Programmers Name and ID\n");
printf("Enter 2 to Perform Integer Operation\n");
printf("Enter 3 to Perform Floating Point Operation\n");
scanf("%d", &choice);
getchar();
if (choice == 1)

    printf("Connor \n000000000\n");


else if (choice == 2)


{
    char c;
    int num1, num2;
    printf("Enter operator:");
    scanf("%c", &c);
    printf("Enter two integer's :");
    scanf("%d %d", &num1, &num2);
    switch (c)
    {

    case '+':
        printf("%d + %d = %d", num1, num2, num1 + num2);
        break;
    case '-':
        printf("%d - %d = %d", num1, num2, num1 - num2);
        break;
    case '*':
        printf("%d * %d = %d", num1, num2, num1*num2);
        break;
    case '/':
        printf("%d / %d = %d", num1, num2, num1 / num2);
        break;

    default:
        printf("The value of c = '%c'\n" , c);
        return(0);
    }

}
else if (choice == 3)
    printf("Enter two \n");

}

关于c - Switch case 程序没有给出输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26226199/

相关文章:

android - 指向 stdio FILE 的指针出现编译器错误

c - .o 与 C 中的 .out

c - 编写 C 宏

python - PyAPI_DATA() 宏的解释?

c - 制作我自己的 printf 函数?

c - Eclipse 上的 SDL 问题

c++ - 可以在 C/C++ 中声明但不定义局部变量吗?

c - C 中的 setgid() 调用不起作用

c - 卡在最大无符号短变量提示上

c++ - 防止在 C++ 中递归调用 main()