2013-10-27 118 views
-1

我在這個網站上看到了這兩個錯誤,並試圖更改我的代碼以適應建議的更改,但它們不適用於我的代碼,所以這裏是我的代碼,我希望你們能幫助我。它並不完整,因爲我只完成了任務的一半,但我看不到我迄今爲止所做的工作,因爲它無法正確構建。謝謝!錯誤LNK2019:無法解析的外部符號,致命錯誤LNK1120:1無法解析的外部

#include <stdio.h> 


//int CheckMoney(double *payment, double item_cost); //compares the amount the user has deposited to the price of item selected. It returns 1 if the amount is at least enough to cover the cost, 0 if there is not enough. 
//void GetMoney(double *payment, double item_cost, char selection); //calls CoinMenu function to collect money from the user and CheckMoney function to keep comparing the deposited amount to the item cost. 
//void GetChange(double *payment, double item_cost, double *change); //calculates the amount of change to be returned 
void CoinMenu(double *payment); 
void Quit(char *again); 
void GetCost(char selection, double *item_cost); 
void Menu(char *selection); 

// Displays the list of snack items and prompts for the user’s choice 
void Menu(char *selection) 
{ 
printf("Welcome to the AAA vending machine, where your wishes could come true for less than $2"); 
printf("/nWhich one of our delicious snacks would you like to sink your teeth into?"); 
printf("/nP – Potato Chips  $1.25"); 
printf("/nS - Snickers Bar  $1.35"); 
printf("/nT – Pop Tart   $0.95"); 
printf("/nC – Cookies   $1.50"); 
printf("/nB – Brownie   $1.75"); 
printf("/nN – Nuts    $1.40"); 
printf("Enter your delicious selection here: ",*selection); 
scanf(" %c", &*selection); 

//determine cost of selection 

GetCost(*selection, 0); 
} 

//sets the cost of the purchase based on value in selection 
void GetCost(char selection, double *item_cost) 
{ 

if(selection=='P'||'p') 
{ 
    *item_cost=1.25; 
} 
else if(selection=='S'||'s') 
{ 
    *item_cost=1.35; 
} 
else if(selection=='T'||'t') 
{ 
    *item_cost=0.95; 
} 
else if(selection=='C'||'c') 
{ 
    *item_cost=1.50; 
} 
else if(selection=='B'||'b') 
{ 
    *item_cost=1.75; 
} 
else if(selection=='N'||'n') 
{ 
    *item_cost=1.40; 
} 
else 
{ 
    printf("That is not a valid selection, have a nice day!"); 
    return; 
} 
} 

//displays menu of coins and gets user input of the coins deposited 
void CoinMenu(double *payment) 
{ 
printf("Please deposit your money by the following numbers:"); 
printf("/n1 - $5.00"); 
printf("/n2 - $2.00"); 
printf("/n3 - $1.00"); 
printf("/n4 - $0.25"); 
printf("/n5 - $0.10"); 
printf("/n6 - $0.05"); 
printf("/n7 - $0.01"); 
printf("/nAmount deposited: "); 
scanf(" %c", &*payment); 
} 




void Quit(char *again) 
{ 
printf("Would you like to buy another snack?"); 
printf("/nEnter Y for yes or N for no: ", *again); 
if(*again=='N'||'n') 
{ 
    return; 
} 
else if(*again=='Y'||'y') 
{ 
    void Menu(char *selection); 
} 
} 
+1

你的main()函數在哪裏? –

+2

請發佈錯誤消息的副本/粘貼 - 您發佈的內容會留下一些可能很重要的細節。此外,可能與您的問題相關或不相關的一個問題是''Quit()'函數中的void Menu(char * selection)'行(在發佈代碼的末尾附近)僅僅是一個永遠不會獲取的聲明使用 - 這不是對'Menu()'函數的調用。 –

回答

0

對於你的問題中提到的錯誤 - 你沒有main()功能,直到你寫一個你沒有一個完整的C程序。您的鏈接器正在查找它,並在找不到它時給出錯誤信息。

還有很多其他的錯誤在這裏,其中包括:

  1. printf("/n1 - $5.00"); - 這是\n,不/n,並且目前還不清楚爲什麼你把換行符在該行的開始,而不是結尾:printf("/nN – Nuts $1.40"); printf("Enter your delicious selection here: ",*selection);會給你看一些奇怪的文字,例如。

  2. 說到其中,printf("Enter your delicious selection here: ",*selection); - 您提供char作爲參數傳遞給printf(),但根據您的格式字符串,它不希望任何參數。應該是printf("Enter your delicious selection here: ");由於您沒有使用換行符終止它,因此您在致電scanf()之前還應該添加fflush(stdout);

  3. scanf(" %c", &*selection); - 爲什麼取消引用一個指針只能再次獲取它的地址?有一些不好的理由,包括這樣做的事實,即它等於將非法臨時價值的地址。你已經有一個指針,所以用它 - 應該是scanf(" %c", selection);

  4. if(selection=='P'||'p') - 二元邏輯運算符不一樣,在C工作,應該是if (selection == 'P' || selection == 'p')

  5. scanf(" %c", &*payment); - 同樣的問題與以上3點,再加上這裏paymentdouble *,和你告訴scanf()閱讀char。應該scanf("%lf", payment);

  6. void Menu(char *selection);底部 - 如在評論你的主要提問時指出,這是一個函數聲明,而不是函數調用,並在這裏有效地什麼都不做。應該是Menu(again),雖然它應該只是返回true或false,並且調用者應該決定是否再次調用Menu()

這些錯誤中的幾個在整個代碼中的不同位置重複出現,我沒有列出每個示例。這些指針的傳遞也是非常奇怪的設計。你所有的函數聲明爲返回void - 如果你改變它們返回一個值並使用一些局部變量,你可以避免傳遞任何指針。

相關問題