How would I go about making a structure global? I get that you put it before int main() but when I try this I don't know what I'm doing wrong here's an example.
struct Store
{
char ISBN [SIZE];
char title [SIZE];
char author [SIZE];
char publisher [SIZE];
char dateAdded [SIZE];
int onHand;
double wholeCost;
double retailCost;
};
char BookInfo()
{
Store BookInfo;
cout<<"Enter the book's ISBN number: \n";
cin.getline(BookInfo.ISBN, SIZE);
cout<<"Enter the title of the book: \n";
cin.getline(BookInfo.title, SIZE);
cout<<"Enter the author of the book: \n";
cin.getline(BookInfo.author, SIZE);
cout<<"Enter the publisher of the book: \n";
cin.getline(BookInfo.publisher,SIZE);
cout<<"Enter the date the book was added: \n";
cin.getline(BookInfo.dateAdded, SIZE);
cout<<"Enter the quantity of this book on hand: \n";
cin>>BookInfo.onHand;
cout<<"Enter the wholesale cost of the book: \n";
cin>>BookInfo.wholeCost;
cout<<"Enter the retail cost of the book: \n";
cin>>BookInfo.retailCost;
system ("pause");
return 0;
};
// The Main Module.
int main ()
{
int selection;
cout << fixed << showpoint << setprecision(2);
do
{
selection = menu();
switch(selection)
{
case 1 : CashierMod();
break;
case 2 : InventoryMod();
break;
case 3 : ReportMod();
break;
case 4 : BookInfo();
break;
case 5 : cout << "Exiting program.\n\n";
}
} while (selection != 5);
return 0;
}
Again I'm not exactly sure how to get it to be global.
Store BookInfo;
char fBookInfo()
{
cout<<"Enter the book's ISBN number: \n";
cin.getline(BookInfo.ISBN, SIZE);
cout<<"Enter the title of the book: \n";
cin.getline(BookInfo.title, SIZE);
cout<<"Enter the author of the book: \n";
cin.getline(BookInfo.author, SIZE);
cout<<"Enter the publisher of the book: \n";
cin.getline(BookInfo.publisher,SIZE);
cout<<"Enter the date the book was added: \n";
cin.getline(BookInfo.dateAdded, SIZE);
cout<<"Enter the quantity of this book on hand: \n";
cin>>BookInfo.onHand;
cout<<"Enter the wholesale cost of the book: \n";
cin>>BookInfo.wholeCost;
cout<<"Enter the retail cost of the book: \n";
cin>>BookInfo.retailCost;
system ("pause");
return 0;
};
How would I go about making it global for multiple books. I'm trying to get it to loop 10 times before the program starts to store all of my info. And then get it to go to int main(). Thanks
struct Store
{
char ISBN [SIZE];
char title [SIZE];
char author [SIZE];
char publisher [SIZE];
char dateAdded [SIZE];
int onHand;
double wholeCost;
double retailCost;
};
Store BookInput;
char BookInput()
{
int n;
Store BookInput;
for (n=0; n<NUM_BOOKS;n++)
{
cout<<"Enter the book's ISBN number: \n";
cin.getline(BookInput.ISBN, SIZE);
cout<<"Enter the title of the book: \n";
cin.getline(BookInput.title, SIZE);
cout<<"Enter the author of the book: \n";
cin.getline(BookInput.author, SIZE);
cout<<"Enter the publisher of the book: \n";
cin.getline(BookInput.publisher,SIZE);
cout<<"Enter the date the book was added: \n";
cin.getline(BookInput.dateAdded, SIZE);
cout<<"Enter the quantity of this book on hand: \n";
cin>>BookInput.onHand;
cout<<"Enter the wholesale cost of the book: \n";
cin>>BookInput.wholeCost;
cout<<"Enter the retail cost of the book: \n";
cin>>BookInput.retailCost;
}
system ("pause");
return 0;
};