a structure code not working please help

#include<iostream>
using namespace std;
struct complex
{
int real;
int imag;
};
int display(complex);
int read (complex);
int main()
{
complex l;
read(l);
display(l);
}
int read(complex l)
{
cout<<"enter the real part : ";
cin>>l.real;cout<<endl;
cout<<"enter the imag part : ";
cin>>l.imag;cout<<endl;
}
int display(complex l)
{
cout<<"real part is : "<<l.real<<endl;
cout<<"imag part is : "<<l.imag<<endl;
}
Last edited on
how can i upload a picture to show u the error in this forum ?
uhm, you might want to actually read in the complex var, but you make a call-by-value so when passing the complex var, you make a copy and so the Value that you read in is only changed in the copy of the complex var.

try passing it as reference, then the passed object gets modified
int read(complex& l)

Also, your methods are declared as "int" but they don't return anything, you might want to change your function declerations to void
1
2
3
4
5
6
7
void display(complex I);
void read (complex& I);
...
void read(complex& l)
{ ... }
void display(complex I)
{ ... }


Usually you just copy the error message in here ^^
Note: please use the <> Symbol on the right of the text field under "Format" to display code, it is much easier to read
Last edited on
Topic archived. No new replies allowed.