I was wondering if I can get a little bit of help. I keep getting a fatal error and I'm not sure where in my code it's happening. I was wondering if somebody can take a look at it and help he see where it's at:
void menu();
char getCommand();
void exeCommand(Cart [], int &, char);
void addItem(Cart [], int &);
void showList(Cart [], int &);
void findCart(Cart [], int &);
void loadData(Cart [], int &);
void addItem(ifstream &, Cart [], int &);
void saveData(Cart [], int &);
int main(void)
{
Cart shopping[CAP];
int size = 0;
char option;
loadData(shopping, size);
do
{
menu();
option = getCommand();
exeCommand(shopping, size, option);
}while(tolower(option) != 'q');
}
void menu()
{
cout << "Welcome to Smart Shopping Cart! :\n"
<< "(a) to add an item\n"
<< "(s) to show the items list\n"
<< "(f) to find an item by item name\n"
<< "(q) to quit\n";
cout << "Please enter an option: ";
}
char getCommand()
{
char ans;
cin.get(ans);
switch (tolower(ans))
{
case 'a':
case 's':
case 'f':
case 'q':
cin.ignore(100, '\n');
return ans;
default:
cout << "Illegal input.";
cin.clear();
cin.ignore(100, '\n');
system("cls");
menu();
return getCommand();
}
}
void exeCommand(Cart list[], int &size, char ans)
{
switch(tolower(ans))
{
case 'a':
addItem(list, size);
saveData(list, size);
break;
case 's':
showList(list, size);
break;
case 'f':
findCart(list, size);
break;
case 'q':
cout << "Thanks for using Smart Shopping Cart. Goodbye!" << endl;
return;
default:
return;
}
}
void loadData(Cart list[], int &size)
{
ifstream inFile;
inFile.open("ShoppingCart.txt");
if(!inFile)
{
cout << "File did not open! Program terminating!" << endl;
exit(1);
}
while(!inFile.eof())
{
addItem(inFile, list, size);
}
}
void showList(Cart list[], int &size)
{
int i;
for(i = 0; i < size; i++)
{
cout << left << list[i].itemName << ";"
<< left << list[i].itemPrice << ";"
<< left << list[i].itemTotal << endl;
}
}
void saveData(Cart list[], int &size)
{
int i = 0;
ofstream outFile;
outFile.open("ShoppingCart.txt");
if(!outFile)
{
cout << "File did not open! Program terminating!" << endl;
exit(1);
}
{
int i = 0;
char junk;
char shopping[MAXCHAR];
cout << "This will allow you to search for an item in a shopping cart." << endl;
cout << "Enter Item Name (less than 101 characters.): ";
cin.get(shopping, MAXCHAR, '\n');
cin.get(junk);
if (strcmp(list[i].itemName, shopping) == 0)
cout << "found it";
}
And this is what I keep getting:
MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup
C:\Users\Brian Williams\Desktop\ShoppingCart\Debug\ShoppingCart.exe : fatal error LNK1120: 1 unresolved externals
WinMain is the entry point in GUI projects, what you have looks like a console application.
So create a new project and choose new console application from visual studio templates this time, NOT GUI application.
Thanks. Now its working. However, the problem that I'm having now is it's giving me the command prompt from void loadData instead of it doing everything else. Is there something else that I need to add in order for it to run the entire program?javascript:editbox1.editSend()