This is supposed to be a code for a video game store
#include<iostream>
#include<fstream>
using namespace std;
ifstream infile;
struct VideoGame
{
string Name;
string Genre;
string Publisher;
string Developer;
string Platform;
string Price;
int count;
VideoGame *link;
};
void CreateList(VideoGame*& first, VideoGame*& last);
void CheckOut(VideoGame*& first, string title);
bool CheckTitle(VideoGame*& first, string title);
void CheckIn(VideoGame*& first, string title);
void InStock (VideoGame*& first, string title);
void PrintTitle(VideoGame*& first);
void PrintList( VideoGame*& first);
void ShowMenu();
int main()
{
if(!infile)
{
cout<<"no file "<<endl;
}
string title;
int selection;
VideoGame *first, *last;
CreateList(first,last);
do
{
ShowMenu();
cin>>selection;
switch(selection)
{
case 1:
cout<<"You have chosen to search if a video game title exist \nEnter the Video Game Title"<<endl;
getline(cin,title);
if(CheckTitle(first,title))
cout<<title<<" is currently in stock"<<endl;
else
{
cout<<title<<" is not available in this store \n Please check your spelling"<<endl;
}
cout<<endl;
break;
case 2:
cout<<"You are checking out a video game \n Enter the title of the video game"<<endl;
getline(cin,title);
if(CheckTitle(first,title))
{
CheckOut(first,title);
}
else
{
cout<<title<<" is not in stock \n Please check your spelling"<<endl;
}
break;
case 3:
cout<<"You are checking in a video game \n Enter the title of the video game"<<endl;
getline(cin,title);
if(CheckTitle(first,title))
{
CheckIn(first,title);
}
else
{
cout<<title<<" is not available in this store \n Please check your spelling"<<endl;
}
break;
case 4:
cout<<"You are checking if a video game title is in stock \n Enter the title of the video game"<<endl;
getline(cin,title);
if(CheckTitle(first,title))
{
InStock(first,title);
}
else
{
cout<<title<<" is not available in this store \n Please check your spelling"<<endl;
}
break;
case 5:
cout<<" These are the titles currently in our stores"<<endl;
PrintTitle(first);
break;
case 6:
cout<<" This is the Inventory"<<endl;
PrintList(first);
break;
case 9:
cout<<"Thank you, Have a Nice Day :)"<<endl;
default:
cout<<"Invalid Selection"<<endl;
}
}
while(selection!=9);
system("pause");
return 0;
}
void CreateList(VideoGame*& first, VideoGame*& last)
{
infile.open("Project6.txt");
first=NULL;
last=NULL;
VideoGame *newnode;
string Name1;
string Genre1;
string Publisher1;
string Developer1;
string Platform1;
string Price1;
int count1;
while(infile)
{
newnode = new VideoGame;
getline(infile,Name1);
getline(infile,Genre1);
getline(infile,Developer1);
getline(infile,Publisher1);
getline(infile,Platform1);
getline(infile,Price1);
infile>>count1;
newnode->Name=Name1;
newnode->Genre=Genre1;
newnode->Publisher=Publisher1;
newnode->Developer=Developer1;
newnode->Platform=Platform1;
newnode->Price=Price1;
newnode->count=count1;
newnode->link=NULL;
if(first==NULL)
{
first=newnode;
last=newnode;
}
else
{
last->link=newnode;
last=newnode;
}
}
}
void ShowMenu()
{
cout<<"----Menu----"<<endl;
cout<<"\"1\" - to check if a title is in store"<<endl;
cout<<"\"2\" - to check out a video game"<<endl;
cout<<"\"3\" - to check in a video game"<<endl;
cout<<"\"4\" - to see if a title is in stock"<<endl;
cout<<"\"5\" - to print the video game titles"<<endl;
cout<<"\"6\" - to print the inventory"<<endl;
}
bool CheckTitle(VideoGame*& first, string title)
{
VideoGame *current;
current=first;
while(current!=NULL)
{
if(current->Name==title)
return true;
else
return false;
current=current->link;
}
}
void CheckOut(VideoGame*& first, string title)
{
VideoGame *current;
current=first;
while(current!=NULL)
{
if(current->Name==title)
{
if(current->count>0)
{
current->count--;
cout<<"Enjoy your "<<title<<endl;
}
else
cout<<title<<" is out of stock"<<endl;
}
current=current->link;
}
cout<<endl;
}
void CheckIn (VideoGame*& first, string title)
{
VideoGame *current;
current=first;
while(current!=NULL)
{
if(current->Name==title)
{
if(current->count>0)
{
current->count++;
cout<<"Thank you for trading in your "<<title<<endl;
}
}
current=current->link;
}
cout<<endl;
}
void InStock (VideoGame*& first, string title)
{
VideoGame *current;
current=first;
while(current!=NULL)
{
if(current->Name==title)
{
if(current->count>0)
cout<<title<<" is in stock"<<endl;
else
cout<<title<<" is not in stock"<<endl;
}
current=current->link;
}
cout<<endl;
}
void PrintTitle(VideoGame*& first)
{
VideoGame *current;
current = first;
while (current != NULL)
{
cout << current->Name<<endl;
current = current->link;
}
cout<<endl;
}
void PrintList( VideoGame*& first)
{
VideoGame *current;
current = first;
while (current != NULL)
{
cout <<"Name :"<<current->Name <<"\n" <<"Genre(s) :"<< current->Genre
<<"\n" <<"Publisher(s) :"<<current->Publisher
<<"\n"<<"Developer(s) :"<<current->Developer<<"\n"<<"Platform(s) :"
<<current->Platform <<"\n"<<"Price :"<<current->Price<<"\n"
<<"In Stock :"<<current->count<<endl;
current = current->link;
}
cout<<endl;
}
This is my infile
Halo: Reach
First Person Shooter
Bungie
Microsoft Game Studios
Xbox 360
$ 59.99
7
BlazBlue: Calamity Trigger
Fighting
Arc System Works
Arc System Works / Aksys Games / pQube & Zen United
Arcade / PlayStation 3, PlayStation Portable, Xbox 360 / Games for Windows
$ 19.99
2
Resident Evil 5
Third-person shooter / survival horror
Capcom
Capcom
Xbox 360 / PlayStation 3 / Microsoft Windows
$ 29.99
0
Grand Theft Auto IV
Free-Roaming Sandbox / Action-Adventure Third Person Shooter
Rockstar North / Rockstar Toronto
Rockstar Games, Take-Two Interactive
$ 19.98
5
something is wrong with create list