Netbeans ツールを構成したところ、(最終的に) 動作しました :) (Hello World で確認しました)。私たちはシフトしていたので、3か月ほどのギャップがあったので、回文チェッカーやブレブレブレなどの他のプログラムではなく、計算機を作成したいと思いました。コードは次のとおりです。
#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' として明確に定義しました! みんなありがとう :)