Need HELP!!!! passing structure arrays to functions


Description: Use functions and structures to simulate storage in a warehouse
*/
#include <cstdlib>
#include<iostream>
#include<cmath>
#include<iomanip>
#include<string>
using namespace std;

struct Bin {std::string name; int Quantity;}; //create a structure for "Bin"

void func_pop(Bin[],int);
void func_disp(Bin[],int);
void func_add(Bin[],int);
void func_subt(Bin[],int);

int main()
{
int count=2;
int Flag=1;
int choice=0;
int i=0;
Bin Item[count];

func_pop(Item,count);
func_disp(Item,count);

while (Flag=1)
{
cout<< "would you like to display Quantitys(1), add(2), subtract(3) or Exit (Enter)"<< endl;
cin>> choice;

while (choice<0||choice>3){cout<< "invalid input try again."<<endl; cout<<" would you like to display Quantitys(1), add(2), subtract(3) or Exit (Enter)"<<endl; cin>>choice;

switch(choice) {
case 1:
func_disp(Item,count);
break;
case 2:
func_add(Item,count);
break;
case 3:
func_subt(Item,count);
break;
default:
cout<< "are you sure you want to quit yes(0) no(1)"<<endl;
cin>> Flag;
}}
system ("pause");
return 0;
}





void func_pop (Bin Item[], int count);
{
int i=0;
while (i<count)
{
cout<< "please enter the name of the Item "<<endl;
cin>> Item[i].name;

cout<< "please enter the quantity of "<<Item[i].name<<" in the bin"<<endl;
cin>> Item[i].Quantity;

while (Item[i].Quantity<0 || Item[i].Quantity>30)
{cout<< "invalid input, please try again"<<endl;cin>> Item[i].Quantity;
}i++;
}





void func_disp (Bin Item[], int count);
{
int i=0;
cout<< "_______________________________________________________"<<endl;
cout<< "Name of Item Quantity"<<endl;
while (i<count)
{
cout<< setw(12)<<Item[i].name<<" "<<Item[i].Quantity<<endl;
i++; }
}





void func_add (Bin Item[], int count) ;
{
int i=0;
int choice=0;
int flag=0;
int add=0;
while (flag=0)
{
cout<< "please choose the Item you would like to add to"<<endl;

while (i<count)
{
cout<< "select "<< i+1<<" for "<< Item[i].name;
i++;
}

cout<<" or 0 for none"<<endl;

cin>> choice;
if (choice> count || choice<0){
while (choice> count || choice<0)
{
cout<< " invalid option please try again"<<endl;
cin>> choice;
}}

else if (choice< count or choice>0)
{
cout<< "how much would you like to add to " <<Item[choice-1].name<< " the current quantity is " <<Item[choice-1].Quantity <<endl;
cin>> add;
while ((Item[choice-1].Quantity+add)>30 || (Item[choice-1].Quantity+add)<0)
{
cout<< "invalid input, count must be between 0 and 30, your count is " <<Item[choice-1].Quantity+add<< " try again"<<endl;
cin>> add;
}
Item[choice-1].Quantity=Item[choice-1].Quantity+add;
cout<< "your new count for "<<Item[choice-1].name<< " is " <<Item[choice-1].Quantity<<endl;
cout<< "would you like to add more? select 0 for yes or 1 for no."<<endl;
cin>> flag;}
else {
cout<< "are you sure you don't want to add anything? press 1 to go to main menu or 0 to try again"<<endl;
cin>> flag;
}}}



void func_subt (Bin Item[],int count) ;
{
int i=0;
int choice=0;
int flag=0;
int Subtract=0;
while (flag=0)
{
cout<< "please choose the Item you would like to Subtract from"<<endl;

while (i<count)
{
cout<< "select "<< i+1<<" for "<< Item[i].name;
i++;
}

cout<<" or 0 for none"<<endl;

cin>> choice;
if (choice> count || choice<0){
while (choice> count || choice<0)
{
cout<< " invalid option please try again"<<endl;
cin>> choice;
}}

else if (choice< count or choice>0)
{
cout<< "how much would you like to Subtract from " <<Item[choice-1].name<< " the current quantity is " <<Item[choice-1].Quantity <<endl;
cin>> Subtract;
while ((Item[choice-1].Quantity+Subtract)>30 || (Item[choice-1].Quantity+Subtract)<0)
{
cout<< "invalid input, count must be between 0 and 30, your count is " <<Item[choice-1].Quantity+Subtract<< " try again"<<endl;
cin>> Subtract;
}
Item[choice-1].Quantity=Item[choice-1].Quantity+Subtract;
cout<< "your new count for "<<Item[choice-1].name<< " is " <<Item[choice-1].Quantity<<endl;
cout<< "would you like to Subtract more? select 0 for yes or 1 for no."<<endl;
cin>> flag;}
else{

cout<< "are you sure you don't want to Subtract anything? press 1 to go to main menu or 0 to try again"<<endl;
cin>> flag;}
}}}









I keep getting a linker error on every function. what am I doing wrong?
You're array of Bin "Item" is of type Bin* (pointer to Bin), because it is an array... so your functions should expect a parameter that is of type Bin* instead of Bin[]. Bin[] seems to mean "array of Bin", which would be logical, but it's an invalid statement.

See "Pointers and arrays" in http://www.cplusplus.com/doc/tutorial/pointers/

AeonFlux
Last edited on
I just found out that there's nothing wrong with the syntax you're using, and that your mistake is actually the ';' after the function's definition header. After the declaration it's ok but not in the definition. Sorry about that :-)
Last edited on
Topic archived. No new replies allowed.