which is of non-class type

Hi guys please help me, why in blj.sub and blj.hrg error which is of non-class type ?

struct data{
int jumlah[30];
int hrg[30];
int sub[30];
char barang[30];
int jum_beli, bayar,diskon;
float tot;


cout<<"Nama Barang : "; fflush(stdin);
gets(blj.barang); //Pengguna input nama barang disimpan pada array nama_barang

cout<<"Jumlah : ";
cin>>blj[i].jumlah; //Pengguna input jumlah disimpan pada array jumlah

cout<<"Harga : ";
cin>>blj[i].hrg; //Pengguna input harga disimpan pada array harga

blj[i].sub=blj.jumlah*blj.hrg; // Menjumlahkan Harga sub total barang
tot=blj.sub; //Menjumlahkan seluruh sub total barang
}

cout<<endl;
cout<<"STRUK BELANJA MINI MARKET ABC"<<endl;
cout<<"---------------------------------------------------------"<<endl;
cout<<"No Barang Jumlah Harga Sub Total"<<endl;
for (int i=0;i<jum_beli;i++){
cout<<i+1<<setw(8)<<blj.barang<<setw(10)<<blj.jumlah<<setw(12)<<blj.hrg<<setw(12)<<blj.sub<<endl; //Menampilkan semua nilai array
}
cout<<"---------------------------------------------------------"<<endl;[/code]
Last edited on
Your struct, data. It doesn't have a closing }

This code contains no functions. It makes no sense. Where is it supposed to start?
i done to write } in struct, but still error in blj.hrg and blj.sub

program.cpp:47:70: error: request for member 'hrg' in 'blj', which is of non-class type 'main()::data [30]'
program.cpp:47:89: error: request for member 'sub' in 'blj', which is of non-class type 'main()::data [30]'

cout<<i+1<<setw(8)<<blj.barang<<setw(10)<<blj.jumlah<<setw(12)<<blj.hrg<<setw(12)<<blj.sub<<endl;
Last edited on
blj.hrg is effectively a pointer-to-int. Same for blj.sub


tot=blj.sub;

tot is a float.
blj.sub is a pointer-to-int.


tot=blj.sub; makes no sense.
i change float tot to int tot
struct data{
int jumlah[30];
int hrg[30];
int sub[30];
char barang[30];
}blj[30];

int jum_beli, bayar,diskon,tot;

and i'm sorry for my mistake, i mean :
blj[i].sub=blj.jumlah*blj.hrg;
tot+=blj.sub;

but still error in cout<<i+1<<setw(8)<<blj.barang<<setw(10)<<blj.jumlah<<setw(12)<<blj.hrg<<setw(12)<<blj.sub<<endl;
blj.jumlah is a pointer-to-int.

When you do this:
cout << blj.jumlah

it makes no sense. What are you trying to do?
Since all the parts of your struct are arrays you should read this tutorial about arrays first.
http://www.cplusplus.com/doc/tutorial/arrays/
Topic archived. No new replies allowed.