2013-10-27 122 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 - 如果你改变它们返回一个值并使用一些局部变量,你可以避免传递任何指针。

相关问题