This is my code...
i'm getting error that "Primary expression missing" in all places where i have ritn desc[i].code or desc[i].cost.
May be i'm using wrong syntax for strcutures;

#include<iostream>
#include<conio.h>
using namespace std;
struct desc
{
       int code;
       int cost;
};

void del(int x, int count)
{
     int i;
     for (i=0;i<count;i++)
     {
         if(desc[i].code==x)
         {
                            desc[i].cost=0;
         }
     }
     cout<<"Item deleted"<<endl;

}

void total( int count)
{
     int i;
     for(i=0;i<count;i++)
     int sum=sum+desc[i].cost;
     cout<<"Total item cost till now is: "<<sum;
}

void bill(int count)
{
     int i;
     cout<<"CODE\t"<<"Cost"<<endl;

     for(i=0;i<count;i++)
     {
                         cout<<desc[i].code<<"\t"<<desc[i].cost<<endl;
     }
     total();
}



int main()
{
    cout<<"Welcome to departmental store";
    int ch, count=0, desc[10];

    while(1)
    {
            cout<<"1:To add an item";
            cout<<endl<<"2:To delete an item";
            cout<<endl<<"3:To view total amount";
            cout<<endl<<"4:To view bill";
            cout<<endl;
            cin>>ch;
            switch(ch)
            {
                      case 1:
                           cout<<"Enter code number of item"<<endl;
                           cin>>desc[count].code;
                           cout<<"Enter cost of item"<<endl;
                           cin>>desc[count].cost;

                           count++;
                           break;
                      case 2:
                           cout<<"Enter code to delete"<<endl;

                           cin>>x;
                           del(x,count);
                           break;
                      case 3:
                           total(count);
                           break;
                      case 4:
                           viewbill(count);
                           break;
                      default:
                              exit 0;
            }
            getch();
    }
}

there is a typename desc as struct
and a variable desc of type int
you must have something like this

struct desc {
...
};

desc list[10];

and use
list[i].code

Edited 3 Years Ago by thendrluca

Comments
Thank u thendrluca...! It was a simple silly mistake.. :P i made a typename desc.. but didnt made a variable of that type... Thnxx... :)

int ch, count=0, desc[10];

This is wrong decleration for desc, what you want as suggested is

 const int MAX_SIZE  = 10;
 desc descriptions[MAX_SIZE]

Then on each function you will pass in descriptions and MAX_SIZE like so

 void del(desc[] descriptions, const int MAX_SIZE, int targetCode){
       for(int i = 0; i < MAX_SIZE; ++i){
             if(descriptions[i].code == targetCode){
                descriptions[i] = 0;
             }
       }
 }

Then you can call it like so

  int x = 0;
  cout << "Enter code to delete: ";
  cin >> x;
  del(descriptions,MAX_SIZE,x);

Thank u thendrluca...!
It was a simple silly mistake.. :P
i made a typename desc..
but didnt made a variable of that type...
Thnxx... :)

This article has been dead for over six months. Start a new discussion instead.