主题:新手求助。。这道题中complex类型的结构体为什么放在main函数中就出错??
这是个用结构体来实现复数的加减乘运算的程序
问题见标题
求解答~~~!
#include<iostream.h>
struct complex
{
float real,image;
}s1,s2;
void add(complex a,complex b)
{
complex c;
c.image=a.image+b.image;
c.real=a.real+b.real;
cout<<c.real<<" "<<c.image;
}
void minus(complex a,complex b)
{
complex c;
c.image=a.image-b.image;
c.real=a.real-b.real;
cout<<c.real<<" "<<c.image;
}
void times(complex a,complex b)
{
complex c;
c.real=a.real*b.real-a.image*b.image;
c.image=a.real*b.image+b.real*a.image;
cout<<c.real<<" "<<c.image;
}
void main()
{
complex s1,s2;
cout<<"please enter the 2 complex:"<<endl;
cin>>s1.real>>s1.image>>s2.real>>s2.image;
add(s1,s2);
minus(s1,s2);
times(s1,s2);
}
问题见标题
求解答~~~!
#include<iostream.h>
struct complex
{
float real,image;
}s1,s2;
void add(complex a,complex b)
{
complex c;
c.image=a.image+b.image;
c.real=a.real+b.real;
cout<<c.real<<" "<<c.image;
}
void minus(complex a,complex b)
{
complex c;
c.image=a.image-b.image;
c.real=a.real-b.real;
cout<<c.real<<" "<<c.image;
}
void times(complex a,complex b)
{
complex c;
c.real=a.real*b.real-a.image*b.image;
c.image=a.real*b.image+b.real*a.image;
cout<<c.real<<" "<<c.image;
}
void main()
{
complex s1,s2;
cout<<"please enter the 2 complex:"<<endl;
cin>>s1.real>>s1.image>>s2.real>>s2.image;
add(s1,s2);
minus(s1,s2);
times(s1,s2);
}