1
最近再次拿起編程。我是一名初學者。我帶了一個課,但現在正在嘗試編譯和運行我在Flash上使用Dev C++在課堂上運行良好的程序。我現在正在家裏使用最新版本的Code :: Blocks。代碼庫缺失庫:blocks
下面是程序代碼一個簡單的計算器程序如下:
/* This program adds, subtracts, multiplies, and divides two integers. */
#include <stdio.h>
#include <stdlib.h>
// Function Declarations
int getOption(void);
void getData (int* a, int* b);
float calc (int option, int num1, int num2);
float add (float num1, float num2);
float sub (float num1, float num2);
float mul (float num1, float num2);
divn (float num1, float num2);
void printResult (float num1, float num2, float result, int option);
int main (void)
{
// Local Declarations
int done = 0;
int option;
int num1;
int num2;
int result;
// Statements
while (!done)
{
option = getOption();
if (option == 5)
done = 1;
else
{
do
{
printf("\n\nEnter two numbers: ");
scanf("%f %f", &num1, &num2);
if (option == 4 && num2 == 0)
{
printf("\a\n *** Error *** ");
printf("Second Number cannot be 0\n");
} //if
} while (option == 4 && num2 == 0);
switch (option)
{
case 1: result = add (num1, num2);
break;
case 2: result = sub (num1, num2);
break;
case 3: result = mul (num1, num2);
break;
case 4: result = divn (num1, num2);
} // switch
printResult (num1, num2, result, option);
} // else option != 5
} // while
printf("\nThank you for using Calculator.\n");
return 0;
} // main
/* ========================= getOption ===================================
This function shows a menu and reads the user option.
Pre nothing
Post returns a valid option */
int getOption (void)
{
// Local Declarations
int option;
// Statements
do
{
printf("\n******************");
printf("\n* Menu *");
printf("\n* *");
printf("\n* 1. ADD *");
printf("\n* 2. SUBTRACT *");
printf("\n* 3. MULTIPLY *");
printf("\n* 4. DIVIDE *");
printf("\n* 5. QUIT *");
printf("\n* *");
printf("\n******************");
printf("\n\n\nPlease type your choice ");
printf("and press the return key : ");
scanf("%d", &option);
if (option < 1 || option > 5);
printf("Invalid option. Please re-enter.\n");
} while (option < 1 || option > 5);
return option;
} // getoption
得到以下編譯錯誤,當我嘗試編譯:
C:\Users\Christopher\SkyDrive\School\Programming\Practice Stuff\complete calculator.o:complete calculator.c|| undefined reference to `add'|
C:\Users\Christopher\SkyDrive\School\Programming\Practice Stuff\complete calculator.o:complete calculator.c|| undefined reference to `sub'|
C:\Users\Christopher\SkyDrive\School\Programming\Practice Stuff\complete calculator.o:complete calculator.c|| undefined reference to `mul'|
C:\Users\Christopher\SkyDrive\School\Programming\Practice Stuff\complete calculator.o:complete calculator.c|| undefined reference to `divn'|
C:\Users\Christopher\SkyDrive\School\Programming\Practice Stuff\complete calculator.o:complete calculator.c|| undefined reference to `printResult'|
||=== Build finished: 5 errors, 0 warnings (0 minutes, 0 seconds) ===|
我相信錯誤是不是因爲代碼錯誤(我知道以前的代碼工作),但因爲我現在使用Code :: Blocks而不是Dev C++,所以我需要引用不同的庫,但不知道我需要哪個庫。
幫助將不勝感激。
add,sub,mul,divn,printResult的_definitions_在哪裏?在另一個.CPP不在項目中? – Jarod42