ERROR: expected primary expression before '*' token
Jan 13, 2019 at 12:02pm UTC
Hey guys, on the line 41 "if(volume_box(BOX *box)>1000)", of my code, I get an error "expected primary expression before '*' token". Could somebody please help me out on this one?
Thanks, Best regards!
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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
#include <iostream>
#include <cstdlib>
#include <cmath>
using namespace std;
typedef struct BOX
{
double length;
double width;
double height;
} BOX;
void create_box(BOX *box)
{
box->length=rand()%101+1;
box->width=rand()%101+1;
box->height=rand()%101+1;
}
void display_box(BOX *box)
{
cout<<"Length: " <<box->length<<"mm" <<endl;
cout<<"Width: " <<box->width<<"mm" <<endl;
cout<<"Height: " <<box->height<<"mm" <<endl;
cout<<endl;
}
double volume_box(BOX *box)
{
double v=box->height * box->length * box->width;
return v;
}
double find_number_box(BOX *box)
{
double volume_counter=0.0;
if (volume_box(BOX *box)>1000);
{
++volume_counter;
}
cout<<"Number of boxes for which volume is greater than 1000 cm^3: " <<volume_counter<<" boxes" <<endl;
return volume_counter;
}
int main()
{
cout << "12B" << endl;
cout<<endl;
int const array_size=400;
BOX array_box[array_size]= {0};
for (int i=0; i<array_size; i++)
{
create_box(&array_box[i]);
display_box(&array_box[i]);
find_number_box(&array_box[i]);
}
return 0;
}
Last edited on Jan 13, 2019 at 12:04pm UTC
Jan 13, 2019 at 12:17pm UTC
It looks like too many BOX....
you passing BOX *box into the function, then you redeclaring it when you call volume_box.
1 2 3 4 5 6 7 8 9 10
double find_number_box(BOX *box)
{
double volume_counter = 0.0;
if (volume_box(box) > 1000);
{
++volume_counter;
}
cout << "Number of boxes for which volume is greater than 1000 cm^3: " << volume_counter << " boxes" << endl;
return volume_counter;
}
Last edited on Jan 13, 2019 at 12:19pm UTC
Jan 13, 2019 at 12:27pm UTC
Thank you so much Grunalin. It works perfectly now.
Topic archived. No new replies allowed.