我對這段代碼有幾個問題。我在代碼的最後列出了錯誤。編譯C代碼時出錯
#include <stdio.h>
int main()
{
void addition(double number1, double number2); /* create the functions */
void subtraction(double number1, double number2);
void division(double number1, double number2);
void multiplication(double number1, double number2);
int inputfunc=1;
double inputnum1=0;
double inputnum2=0;
int number1;
int number2;
int answer;
while (inputfunc >= 1 && inputfunc <= 4) /* If function to be performed are those below then continue performing loop */
{
printf("Press 1 to add two numbers.\n");
printf("Press 2 to subtract two numbers.\n");
printf("Press 3 to multiply two numbers.\n");
printf("Press 4 to divide two numbers.\n");
printf("Press 5 to exit.\n");
printf("Enter your choice\n");
scanf_s("%d", &inputfunc);
if(inputfunc == 5) /* Exit program if requested via 5 function */
return(0);
printf("Enter both numbers with a space in between.");
scanf_s("%lf %lf", &inputnum1, &inputnum2);
void(*func[4])(double, double)={&addition, &subtraction, &division, &multiplication};
(*func[inputfunc-1])(inputnum1, inputnum2);
return(0);
}
}
void addition(double number1, double number2)
{
double answer;
answer=number1+number2;
printf("Addition of the two numbers = %lf + %lf = %lf\n", number1, number2, answer);
return;
}
void subtraction(double number1, double number2)
{
double answer;
answer=number1-number2;
printf("By subtracting the two numbers results are %lf - %lf = %lf\n", number1,
number2, answer);
return;
}
void multiplication(double number1, double number2)
{
double answer;
answer=number1*number2;
printf("By multiplying the two numbers results are %lf * %lf = %lf\n", number1,
number2, answer);
return;
}
void division(double number1, double number2)
{
double answer;
answer=number1/number2;
printf("By dividing the two numbers results are %lf/%lf = %lf\n", number1,
number2, answer);
return ;
}
錯誤C2143:語法錯誤:缺少 ';'之前的「type」 錯誤C2065:FUNC':未聲明的標識符 錯誤C2109:下標要求數組或指針類型
請縮進你的代碼,因爲如果你用腳寫代碼就會發生類似這樣的錯誤。 – bitcell 2014-11-24 07:13:51
搞笑:-)順便說一句,@DonCarter,你可以請upvote那些誰幫助你?這是標準做法,不僅要獎勵他們,而且要向其他人表明實際解決問題的同樣的問題。你可以upvote,也可以接受一個答案, – Mawg 2014-11-24 09:15:39
與一些UniCell不同,我沒有天生的編寫代碼的能力。我發佈的代碼是Word中的複製和粘貼,它並不總是在寫入時進行轉置。初學者應該有更多的耐心。我只在這裏待了三個星期! – 2014-11-25 01:29:08