Hi friends in my following program of c++. I am passing array of structure to function but getting errors in it. Can anybody help please. There are following erros in the program.
1.Constant expression required. 2. Illegal structure operation. 3. Declaration syntax error.
#include<iostream.h>
#include<conio.h>
void calc_price(struct c_items);
struct c_items
{
float name[80];
int quantity;
int price;
};
int main(void)
{
int num_items=3;
c_items obj[num_items]
calc_price(obj,num_items);
getch();
return 0;
}
void calc_price(c_items obj[],int num_items)
{
int i,n,total=0;
cout<<"Enter number of items = ";
cin>>n;
for(i=1;i<=num_items;i++)
{
cout<<"Enter name of item"<<i<<" = ";
cin>>obj[i].name;
cout<<endl<<"Enter price of item"<<i<<" = ";
cin>>obj[i].price;
cout<<endl<<"Enter quantity of item"<<i<<" = ";
cin>>obj[i].quantity;
}
cout<<endl<<endl<<"Retail value of inventory ";
for(i=1;i<=5;i++)
{
cout<<endl<<obj[i].name<<i<<" "<<obj[i].price<<"$";
total=total+obj[i].price;
}
cout<<"Total retail value = "<<total<<"$";
}
calc_price(c_items* obj,int num_items)