Trouble Understanding PARAMETERS of Void Functions

Please tell me what my n00b mistake is. :)
I need to be able to use Void Functions to call upon this coding, for the int main()...

But, I do not know what Parameters require input. :(

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>
#include <fstream>

using namespace std;

struct itemList
{
    string itemName;
    string itemCategory;
    float itemPrice;
    string itemDesigner;
};

void addInfo(); // <- What Goes Here??

int main()
{
blah blah blah
}

void addInfo() // <- What Goes Here??
{
    for (int i = 0; i < listSize; i++)
    {
        cout << "Enter " << i+1 << " Item Name: ";
        cin.ignore();
        getline (cin, itemList[i].itemName);
        
        cout << "Enter " << itemList[i].itemName << "'s Genre: ";
        cin >> itemList[i].itemCategory;
        
        cout << "Enter " << itemList[i].itemName << "'s Price Paid: ";
        cin >> itemList[i].itemPrice;
        
        cout << "Enter " << itemList[i].itemName << "'s Publisher: ";
        cin >> itemList[i].itemDesigner;
    }
}


Any help would be amazing!!
The sooner, the better! :D
by the way; When writing this code...
The "!" or Error's appear to be referring to the "listSize" & "itemList[i]", within my void addInfo section.
You will probably want to insert the arguments: listSize and itemList to your arguments.

So do something like this:
void addInfo(int listSize, itemList &itemList[]);

listSize will be an input and itemList will be an input/output.
I'm still having errors, but that did help improve my understanding quite a bit!

Now, I have...
1
2
void addInfo(int listSize, itemInfo &itemInfo[]);
// The Error is Located right.............../\ HERE! 


It is underlined in Red, meaning Error. "["
It keeps telling me...
"itemInfo" declared as array of references of type "itemInfo &"
Last edited on
Take out the ampersand (&) from the function parameters. Its making the compiler what data type your talking about.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
void addItem(itemInfo itemList[], int listSize);

int main()
{
    ifstream inDatabase;
    ofstream outDatabase;
    
    inDatabase.open("itemDatabase.txt");
    outDatabase.open("itemDatabase.txt");
    
    struct itemInfo;
    int choice;
    
    string item;
    
    itemInfo itemList [Name_Of_Item]; // I have having problems with this line.

    showMenu();
    
    cout << "Enter Number: ";
    cin >> choice;
    
    switch (choice)
    {
        case 1:
            addItem(itemList, Name_Of_Item);
            break;


Okay, so where I mentioned that I am having a problem...
The "Name_Of_Item" is underlined in Red.
It keeps saying, "Use of undeclared identifier "Name_Of_Item""

What do I do? I finally got the other errors to disappear.

ps; THANK YOU for helping me. :)
Last edited on
"Name_Of_Item" was never declared, which is why your having errors. Because your declaring an array, the compiler will want you to put a number there, indicating the size of the array. Just replace "Name_Of_Item" everywhere you use it with a number of your choice.
 
itemInfo itemList [Name_Of_Item]; // I have having problems with this line. 


So, what would I enter in between the "[" and "]" ???
I can't leave it blank, or an error still appears.

Thank you for continuing to help me. :)
Bump BUmp BUMp BUMP
Topic archived. No new replies allowed.