注册 登录
编程论坛 C++教室

总有一处错误 求改错

tlj 发布于 2014-03-12 22:28, 502 次点击
#include<iostream>
using namespace std;
class RMB{
public:
    void setmoney(int newY=8,int newJ=7,int newF=5);
    void showmoney();
private:
    int Yuan,Jiao,Fen;
};
void RMB::setmoney(int newY,int newJ,int  newF){
    Yuan=newY;
    Jiao=newJ;
    Fen=newF;
}
inline void RMB::showmoney(){
    cout<<Yuan<<":"<<Jiao<<":"<<Fen<<endl;
}
int main(){
    RMB myRMB;
    cout<<"first money set and output:"<<endl;
    myRMB.setmoney();
    myRMBshowmoney();
    cout<<second  money set and output:"<<endl;
    myRMB setmoney(3,4,6);
    myRMB showmoney();
    return 0;
}
5 回复
#2
rjsp2014-03-13 11:05
首先,你要学会语言表达,“总有一处错误”别人是根本不知道你想说什么的,你得说清楚点,比如 编译错误,错误信息为……;比如 运行错误,输入……输出……,期待输出……。

其次,你得看书,起码学那么一点点C/C++基础知识再来问问题
像这种
    myRMB.setmoney();
    myRMBshowmoney();
第二句少了个“点”,若凭自己的智力真看不出,那别人教你也没用
还有
    cout<<"first money set and output:"<<endl;
    cout<<second  money set and output:"<<endl;
就是依样画葫芦,也应该能看出第二句少了个“双引号”
其它类同。
#3
三色贝壳2014-03-13 16:58
void RMB::setmoney(int newY,int newJ,int  newF)//参数表和类定义中函数原型声明不一样
{

    Yuan=newY;
    Jiao=newJ;
    Fen=newF;
}
#4
tlj2014-03-13 22:23
回复 2楼 rjsp
谢谢指导
#5
Susake2014-03-13 22:28
看排版还不错...怎么还犯这些小错误?
#6
tlj2014-03-14 19:42
回复 5楼 Susake
初学者   当局者迷
1