error LNK2019: unresolved external symbol, fatal error LNK1120: 1 unresolved externals

StackOverflow https://stackoverflow.com/questions/19614258

  •  01-07-2022
  •  | 
  •  

Question

I have looked both of these errors up on this website and tried to change my code to accommodate the changes that were suggested but they did not work for my code, so here is my code and I hope you guys can help me out. It is not complete as I am only about half way done with the assignment but I cannot see what I have done so far because it won't build correctly. Thank you!

#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);
}
}
Was it helpful?

Solution

For the error mentioned in your question - you have no main() function, and you don't have a complete C program until you write one. Your linker is looking for it, and giving you an error when it can't find it.

There's plenty of other errors here, too, including:

  1. printf("/n1 - $5.00"); - it's \n, not /n, and it's not clear why you're putting the newline at the beginning of the line, instead of the end: printf("/nN – Nuts $1.40"); printf("Enter your delicious selection here: ",*selection); is going to give you some weird looking text, for instance.

  2. Talking of which, printf("Enter your delicious selection here: ",*selection); - you provide a char as an argument to printf(), but according to your format string, it's not expecting any arguments. Should be printf("Enter your delicious selection here: "); Since you're not terminating it with a newline, you should also add an fflush(stdout); before your call to scanf().

  3. scanf(" %c", &*selection); - why dereference a pointer only to take its address again? There are some good reasons not to, including the fact that it amounts to taking the address of a temporary value which is illegal. You already have a pointer, so use it - should be scanf(" %c", selection);

  4. if(selection=='P'||'p') - binary logical operators don't work like that in C, should be if ( selection == 'P' || selection == 'p' ).

  5. scanf(" %c", &*payment); - same issue with as point 3 above, plus here payment is a double *, and you're telling scanf() to read a char. Should be scanf("%lf", payment);

  6. void Menu(char *selection); at the bottom - as pointed out in the comments to your main question, this is a function declaration, not a function call, and effectively does nothing here. Should be Menu(again), although really it should just return true or false, and the caller should decide whether or not to call Menu() again.

Several of these errors are repeated in various places throughout your code, I haven't listed every single example. This passing around of pointers is just really weird design, too. All of your functions are declared as returning void - if you changed them to return a value and employed some local variables, instead, you'd be able to avoid passing any pointers at all.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top