主题:简单的程序调试不对 ,请指教
一道简单的课后习题,程序如下
//ex5-4
//function returns larger of two distances
#include<iostream>
using namespace std;
//English distance
struct Distance{
int feet;
int inches;
};
///////////////////////////////////////////////////////////////////////////////////
//function declaration
Distance compdis(Distance,Distance);
void engdis(Distance);
void iofunc(Distance);
int main(){
Distance d1,d2,d3;
iofunc(d1);
iofunc(d2);
d3=compdis(d1,d2);
cout<<"The largest is :"<<engdis(d3)<<endl;
return 0;
}
//---------------------------------------------------------------------------------
//compdis()
//compares two structures of type Distance,return the larger
Distance compdis(Distance dd1,Distance dd2){
if((dd1.feet=dd2.feet)&(dd1.inches=dd2.inches)){
cout<<"the numbers you enter is the same !";
}else if(dd1.feet>dd2.feet){
return dd1;
}else if(dd1.feet<dd2.feet){
return dd2;
}else if(dd1.inches>dd2.inches){
return dd1;
}else
return dd2;
}
//-----------------------------------------------------------------------------------
//engdis()
//display structure of type Distance in feet and inches
void engdis(Distance dd){
cout<<dd.feet<<"\'"<<dd.inches<<"\""<<endl;
}
//-----------------------------------------------------------------------------------
//iofunc()
//supply the user a interface of input and output
void iofunc(Distance dd){
cout<<"Please enter feet :"<<endl;
cin>>dd.feet;
cout<<"Please enter inches :"<<endl;
cin>>dd.inches;
}
调试后显示exp5-4.cpp(28) : error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'void' (or there is no acceptable conversion) 求教 !
还有个问题:
cout<<"The largest is :"<<engdis(d3)<<endl;这句用cout<<"The largest is :"<<d3.feet<<"\'"<<d3.inches<<endl;替换也就是不用engdis函数,可以否?我调试后数值不对。
谢谢大家了 !
//ex5-4
//function returns larger of two distances
#include<iostream>
using namespace std;
//English distance
struct Distance{
int feet;
int inches;
};
///////////////////////////////////////////////////////////////////////////////////
//function declaration
Distance compdis(Distance,Distance);
void engdis(Distance);
void iofunc(Distance);
int main(){
Distance d1,d2,d3;
iofunc(d1);
iofunc(d2);
d3=compdis(d1,d2);
cout<<"The largest is :"<<engdis(d3)<<endl;
return 0;
}
//---------------------------------------------------------------------------------
//compdis()
//compares two structures of type Distance,return the larger
Distance compdis(Distance dd1,Distance dd2){
if((dd1.feet=dd2.feet)&(dd1.inches=dd2.inches)){
cout<<"the numbers you enter is the same !";
}else if(dd1.feet>dd2.feet){
return dd1;
}else if(dd1.feet<dd2.feet){
return dd2;
}else if(dd1.inches>dd2.inches){
return dd1;
}else
return dd2;
}
//-----------------------------------------------------------------------------------
//engdis()
//display structure of type Distance in feet and inches
void engdis(Distance dd){
cout<<dd.feet<<"\'"<<dd.inches<<"\""<<endl;
}
//-----------------------------------------------------------------------------------
//iofunc()
//supply the user a interface of input and output
void iofunc(Distance dd){
cout<<"Please enter feet :"<<endl;
cin>>dd.feet;
cout<<"Please enter inches :"<<endl;
cin>>dd.inches;
}
调试后显示exp5-4.cpp(28) : error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'void' (or there is no acceptable conversion) 求教 !
还有个问题:
cout<<"The largest is :"<<engdis(d3)<<endl;这句用cout<<"The largest is :"<<d3.feet<<"\'"<<d3.inches<<endl;替换也就是不用engdis函数,可以否?我调试后数值不对。
谢谢大家了 !