Don't know what's the error. Reply fast!

In 83rd line message says: "Illegal Structure operation". But I didn't use any structures!
What's the problem? And how to correct it?
Please reply fast! Its urgent! :|


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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#include<iostream.h>
#include<conio.h>
#include<math.h>
int prime(int);
int reverse(int) ;
int power(int,int);
int rectangle(int,int);
int square(int);
int circle(int);
void tables(int);
void main()
{
 clrscr();
 int p, g, m;
 float q, r, k, l, s, t;
 cout<<"This program executes as per your choice."<<endl;
 cout<<"1. Tells whether a number is prime or not."<<endl;
 cout<<"2. Gives the reverse of the number entered by you."<<endl;
 cout<<"3. Computes x^y (x raised to the power y.)"<<endl;
 cout<<"4  Computes the area of a circle, rectangle or a square"<<endl;
 cout<<"5. Displays the multiplication table of a number upto 1st 10 multiples."<<endl;
 cout<<"Enter your choice : ";
 cin>>g;
 switch(g)
 {
  case 1:
     {cout<<"Number is prime -->1. Number is not a prime-->-1"<<endl;
      cout<<"Enter a number: ";
      cin>>p;
      cout<<prime(p);
     }
	 break;
  case 2:
     {
      cout<<"Enter a number: ";
      cin>>p;
      cout<<reverse(p);
     }
	 break;
  case 3:
     {
      cout<<"Enter a number: ";
      cin>>q;
      cout<<"Enter the power to be raised to: ";
      cin>>r;
      cout<<q<<"^"<<r<<" "<<"is: "<<power(q,r);
     }
	 break;
  case 4:
     {
      cout<<"1. Area of Reactagle."<<endl;
      cout<<"2. Area of Square."<<endl;
      cout<<"3. Area of Circle."<<endl;
      cout<<"Enter choice: "<<endl;
      cin>>m;
      if(m==1)
       {
		  cout<<"Enter length and breadth of the rectangle: ";
		  cin>>k>>l;
		  cout<<"Area of rectangle is: "<<rectangle(l,k);

       }
      if(m==2)
       {
		  cout<<"Enter side of square: ";
		  cin>>s;
		  cout<<"Area of square is: "<<square(s);
       }
      if(m==3)
       {
		  cout<<"Enter radius of circle: ";
		  cin>>t;
		  cout<<"Area of circle is: "<<circle(t);
       }
      else
       cout<<"Wrong choice.";
     }
	 break;
  case(5):
     {
      cout<<"Enter a number: ";
      cin>>p;
      cout<<tables(p);
     }
	 break;
  default:
      cout<<"Wrong choice";
 }//switch case closes
 getch();
}//void main closes
int prime(int a)
{ int flag=0;
  for(int i=2; i<=(a/2); i++)
  {
	  while(flag==0)
	  {
		 if(a%i==0)
		  flag++;
	  }
  }
  if(flag==0)
	  return 1;
  else
	  return -1;
}

int reverse(int b)
{
  int j, flag=0, sum=0, y;
  j=b;
  while(j>0)
  { 
	j=j/10;
	flag++;
  }
  while(b>0)
  {
	y=b%10;
	sum+=y*(pow(10,flag));
	flag--;
	b=b/10;
  }
 return sum;
}
float power(float c, float d)
{
	for(int i=0; i<d; i++)
	{
		c*=c;
	}
 return c;
}
float rectangle(float e, float f)
{
	float ar;
	ar= e*f;
	return ar;
}
float square(float h)
{
	float ar;
	ar=h*h;
	return ar;
}
float circle(float i)
{
	float ar;
	ar=3.14*i*i;
	return ar;
}
void tables(int j)
{
       for(int i=1; i<11; i++)
	{
	  cout<<j<<" x "<<i<<"="<<j*i;
	}
}
Last edited on
instead of

83. cout<<tables(p);

just use

83. tables(p);
> In 83rd line message says: "Illegal Structure operation".
Don't paraphrase.
After fixing your headers (is just `iostream', and `cout' is in the `std' namespace)
$ g++ -W{all,extra} foo.cpp 2>&1 | grep error
foo.cpp:83:11: error: no match for ‘operator<<’ in ‘std::cout << tables(p)’

$ clang++ -W{all,extra} foo.cpp 2>&1 | grep error
foo.cpp:83:11: error: invalid operands to binary expression ('ostream' (aka 'basic_ostream<char>') and 'void')

¿do you understand why cout << tables(p); makes no sense?
Last edited on
Ok did that. But then it gives 4 linker errors:
Undefined symbol circle(int) in module JOINT.CPP
Undefined symbol square(int) in module JOINT.CPP
Undefined symbol rectangle(int, int) in module JOINT .CPP
Undefined symbol power(int, int) in module JOINT.CPP

:| :/
Maybe you'll want to try to respect the prototype.
What do you mean me555?
1
2
3
4
5
6
7
8
9
int power(int,int); //your prototype
float power(float c, float d) //your definition
{
	for(int i=0; i<d; i++)
	{
		c*=c;
	}
 return c;
}
¿Do you see the difference, Vinkerd?
Topic archived. No new replies allowed.