0

我刚刚配置了我的 Netbeans 工具,并且(最终)它工作了:)(我检查了 Hello World)。我们正在转变,所以我有 3 个月的差距,所以我想我会做一个计算器,而不是像回文检查器和 bleh bleh bleh 之类的其他程序。所以这里是代码:

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
void addition(int,int);
void subtraction(int,int);
void  mutiplication(int,int);
void division(int,int);
int main() {
    int x,y,choice,redo = 1;
    while(redo)
    {
    printf("\nWelcome to the CalC :D\nPlease make a choice\n1.Addition\n2.Subtraction\n3.Multiplication\n4.Division\n>");
    scanf("%d",&choice);
    switch(choice);
    {
    case '1' :
        {
            printf("Enter the first number\n>");
            scanf("%d",&x);
            printf("\nThe second number?\n>");
            scanf("%d",&y);
            addition(x,y);
        }
        case '2' :
        {
            printf("Enter the first number\n>");
            scanf("%d",&x);
            printf("\nThe number to be subtracted from %d is?\n>",x);
            scanf("%d",&y);
            subtraction(x,y);
        }
        case '3' :
        {
            printf("Enter the first number\n>");
            scanf("%d",&x);
            printf("\nThe number to be multiplied with %d is?\n>",x);
            scanf("%d",&y);
            multiplication(x,y);

        }

        case '4' :
        {
            printf("Enter the first number\n>");
            scanf("%d",&x);
            printf("\nThe number to be divided by %d is?\n>",x);
            scanf("%d",&y);
            division(x,y);
        }
    }
    printf("\nWould you like to make another calculation?\n1.Yes '_' \n2.No! :p\n>");
    scanf("%d",&redo);

    }
    return (EXIT_SUCCESS);
}

void addition(int x,int y)
{
    int sum;
    sum = x + y;
    printf("\nThe sum of %d and %d is %d\n(Press enter to display the menu)",x,y,sum);
    getch();
}

void subtraction(int x,int y)
{
    int difference;
    ce;
    difference = x - y;
    printf("The difference between %d and %d is %d\n(Press enter to display the        menu)",x,y,difference);
    getch();
}

void multiplication(int x,int y)
{
    int product;
    product = x * y;
    printf("The product of %d and %d is %d\n(Press enter to display the menu)",x,y,product);
    getch();
}

void division(int x,int y)
{
    float quotent;
    quotent = (float)x/(float)y;
    printf("The quotient of %d and %d is %.2f\n(Press enter to display the menu)",x,y,quotent);
    getch();
}

这是我得到的错误:

"/C/MinGW/bin/make.exe" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory 'C:/Users/CaptFuzzyboots/Documents/NetBeansProjects/CalC'
"c:/MinGW/bin/make.exe"  -f nbproject/Makefile-Debug.mk dist/Debug/MinGW-Windows/calc.exe
make[2]: Entering directory 'C:/Users/CaptFuzzyboots/Documents/NetBeansProjects/CalC'
mkdir -p build/Debug/MinGW-Windows
rm -f build/Debug/MinGW-Windows/main.o.d
gcc    -c -g -MMD -MP -MF build/Debug/MinGW-Windows/main.o.d -o build/Debug/MinGW-Windows/main.o main.c
main.c: In function 'main':
main.c:26:5: error: case label not within a switch statement
main.c:34:9: error: case label not within a switch statement
main.c:42:9: error: case label not within a switch statement
main.c:52:9: error: case label not within a switch statement
main.c: In function 'subtraction':
main.c:78:5: error: 'ce' undeclared (first use in this function)
main.c:78:5: note: each undeclared identifier is reported only once for each function it appears in
main.c: At top level:
main.c:83:6: warning: conflicting types for 'multiplication' [enabled by default]
main.c:48:13: note: previous implicit declaration of 'multiplication' was here
nbproject/Makefile-Debug.mk:66: recipe for target 'build/Debug/MinGW-Windows/main.o' failed
make[2]: *** [build/Debug/MinGW-Windows/main.o] Error 1
make[2]: Leaving directory 'C:/Users/CaptFuzzyboots/Documents/NetBeansProjects/CalC'
nbproject/Makefile-Debug.mk:59: recipe for target '.build-conf' failed
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory 'C:/Users/CaptFuzzyboots/Documents/NetBeansProjects/CalC'
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed
make: *** [.build-impl] Error 2


BUILD FAILED (exit value 2, total time: 661ms)

我习惯了编码::blocks所以我真的不知道这里有什么问题:\请帮帮我,我明确地将开关标签定义为'1','2','3','4'!多谢你们 :)

4

4 回答 4

1

后面多了一个分号switch(choice)。你的代码有

switch(choice);

它应该是

switch(choice)

其他几个问题:

multiplication1)您在顶部定义函数时拼写错误。2)你的函数中
有一个流浪者。3)您的陈述中 没有任何陈述(看起来您不希望案例失败,因此您可能需要它们) 4)是一个,但您在s 上使用大小写。由于您正在使用 阅读整数,因此您可能希望拥有而不是.ce;subtraction
breakcase
choiceintcharscanf1,2,3,4'1','2','3','4'

于 2013-08-22T00:55:34.067 回答
0

您的主要问题是switch (choice). 删除该分号,并确保break在每个案例之后都有一个。

您还choice声明为整数,但您的case标签正在打开char; 建议去掉每个案例周围的单引号。

于 2013-08-22T01:17:58.483 回答
0
  1. 切换后删除分号(选择)
  2. 在每种情况下都有一个“休息”
  3. 在开头,正确的乘法拼写
  4. 删除“ce;” 里面的函数减法。
  5. 将案例“1”、“2”等更改为 1、2...
  6. 请注意,如果您在 Eclipse 或其他 IDE 中运行正常的 C 代码,从 Netbeans IDE 运行应该会产生相同的结果。您的错误现在与 Netbeans 无关。
于 2013-08-22T01:13:22.313 回答
0
  • 做案例'1'而不是案例1
  • 写乘法而不是乘法
  • 从减法函数中删除“ce”
于 2013-08-22T00:57:01.337 回答