簡體   English   中英

Netbeans C程序返回值2

[英]Netbeans C program return value 2

我只配置了Netbeans工具,( 終於 )它起作用了:)(我檢查了Hello World)。 我們在換班,所以我有3個月的時間差,所以盡管我會做一個計算器,而不是回文檢查器和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'! 多謝你們 :)

switch(choice)之后,您要使用多余的分號。 您的代碼有

switch(choice);

它應該是

switch(choice)

其他一些問題:

1)在頂部定義函數時,您拼寫了錯誤的multiplication
2)有流浪ce; 在您的subtraction函數中。
3)您的case語句中沒有任何break語句(看來您不希望這些案例失敗,因此您可能需要它們)
4) choice是一個int ,但是你是char 由於您正在使用scanf讀取整數,因此您可能希望使用1,2,3,4而不是'1','2','3','4'

  • 做案例'1'而不是案例1
  • 寫乘法而不是乘法
  • 從減法函數中刪除“ ce”
  1. 切換后刪除分號(選擇)
  2. 在每種情況下都有一個“休息”
  3. 一開始,乘法的正確拼寫
  4. 刪除“ ce;” 內部函數減法。
  5. 將大小寫'1','2'等更改為1,2 ...
  6. 請注意,如果您在Eclipse或某些其他IDE中運行NetBeans IDE,則從NetBeans IDE運行常規C代碼應產生相同的結果。 您的錯誤與Netbeans無關。

您的主要問題是switch (choice)后多余的分號。 刪除該分號,並確保在每種情況下也要break

您還可以choice聲明為整數,但是case標簽正在打開char 最好刪除每種情況下的單引號。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM