#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>
#include <fstream>
usingnamespace std;
struct productInfo
{
string productName;
string productGenre;
float productPrice;
string productPublisher;
int productRating;
int productList;
};
void showMenu();
void addProduct(productInfo productList[], int listSize);
int main()
{
ifstream infile;
ofstream outfile;
int choice;
int index;
int i;
string product;
productInfo productList[?]; // Here is where I am having trouble...
showMenu();
cout << "Enter Number: ";
cin >> choice;
switch (choice)
{
case 1:
addProduct(productList, ?); // "?" represents whatever I need to
break; // enter for the "[?]" listed above...
Well you could read listSize and then do int productList[listSize] or just put productList[666] or any random number. If you cold show me your addProduct I could help you more so sorry if I don't understand what you actually need.
1> How many products do you expect to be added?
2> Is there a max size allowed to be added to the products array?
If you can answer number 1, then you can probably use that as your array size. If the answer of number 2 is yes, then you can guarantee an array size. You can create a const for your array size:
const size_t max_products = 20; //Or something like it.
Then when you use this in your code.
1 2 3 4 5 6 7
int main()
{
const size_t max_products = 20;
//...
productInfo productList[max_products ]; //Using the constant
//...
addProduct(productList, max_products ); //Passing the constant
If you cannot answer number 1, and there is no max size allowed, then you will need to use dynamic allocation and you will not be able to specify your size at compile time (which is required for arrays on the stack).