佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 869|回复: 11

请大家帮小弟看看这程式的ERROR(新的error)

[复制链接]
发表于 9-11-2005 11:46 PM | 显示全部楼层 |阅读模式
小弟的project 是banking system....
小弟大概写了一个draft,可是有5个error解决不到,是compline 后得到的error,
所以,请各位长辈帮忙看看....

//This Peoject is about system banking.
#include<iostream>
#include<fstream>
#include<cstdlib>
using namespace std;


double storemoney(double);
double takeoutmoney(double);
double checking(double);
int main()
{
        int a;
        int sm;
        int tom;
        int cm;

        cout<<"ATM BANK OF EVOLUTION\n\n\n";
        cout<<"1.SAVING\n";
        cout<<"2.DRAWING\n";
        cout<<"3.CHECKING ACCOUNT\n";
        cout<<"4.Quit\n\n";
        cout<<"Please Enter A Number\n";
        cin>>a;

        if (a=1)
                storemoney(sm);
        else if        (a=2)
                takeoutmoney(tom);
        else if (a=3)
                checking(cm);
        else
                cout<<"Thank You\n"<<"Please Come Again\n";


        return 0;
}

//function to store money
double storemoney(double sm)
{
        int earn;
        cout<<"How much you want to store?\n";
        cin>>earn;
        cout>>"You have store <<earn<< in the bank\n";
        cout>>"Your balance in the account is xxx\n";
        return 0;
}

//function to take out money from bank
double takeoutmoney(double tom)
{
        int lose;
        cout<<"How much you want to take out?\n";
        cin >>lose;
        cout>>"You have take out <<lose<< from the bank";
        cout>>"Your balance in the account is xxx\n";
        return 0;
}

//function to checking account
double checking(double cm)
{
        cout>>"Your balance in the bank is xxx\n";
        return 0;
}

[ 本帖最后由 evo9 于 16-11-2005 11:24 PM 编辑 ]
回复

使用道具 举报


ADVERTISEMENT

发表于 10-11-2005 01:01 AM | 显示全部楼层
原帖由 evo9 于 9-11-2005 11:46 PM 发表
小弟的project 是banking system....
小弟大概写了一个draft,可是有5个error解决不到,是compline 后得到的error,
所以,请各位长辈帮忙看看....

//This Peoject is about system banking.
#include<ios ...


cout过后的expression是<<,不是>>
这是我该的几行,不算是大问题,应该是你粗心吧。

cout<<"You have store"<<earn<<" in the bank\n";
cout<<"Your balance in the account is xxx\n";

cout<<"You have take out "<<lose<< "from the bank";
cout<<"Your balance in the account is xxx\n";

cout<<"Your balance in the bank is xxx\n";
回复

使用道具 举报

发表于 10-11-2005 01:14 AM | 显示全部楼层
1.) cout 箭頭方向錯了
double storemoney(double sm)
{
        int earn;
        cout<<"How much you want to store?\n";
        cin>>earn;
        cout>>"You have store <<earn<< in the bank\n";
        cout>>"Your balance in the account is xxx\n";
        return 0;
}

2.) 邏輯錯誤,不是 a=1 , 應該是 a == 1 ,
    這個錯誤很常犯而且很難debug,以後要注意

        if (a=1)
                storemoney(sm);
        else if        (a=2)
                takeoutmoney(tom);
        else if (a=3)
                checking(cm);
        else
                cout<<"Thank You\n"<<"Please Come Again\n";
回复

使用道具 举报

发表于 10-11-2005 01:16 AM | 显示全部楼层
瓦,被搶先了   
回复

使用道具 举报

 楼主| 发表于 10-11-2005 03:31 AM | 显示全部楼层
谢谢大家,请问一下的warning 是什么意思?

Compiling...
main.cpp
C:\Documents and Settings\David\Desktop\banking system Project\main.cpp(27) : warning C4700: local variable 'sm' used without having been initialized
C:\Documents and Settings\David\Desktop\banking system Project\main.cpp(29) : warning C4700: local variable 'tom' used without having been initialized
C:\Documents and Settings\David\Desktop\banking system Project\main.cpp(31) : warning C4700: local variable 'cm' used without having been initialized
回复

使用道具 举报

发表于 10-11-2005 09:28 AM | 显示全部楼层
warning 警告,

initialize 后的 variables
必须给一个value,
否则程序可能会出现问题..
回复

使用道具 举报

Follow Us
 楼主| 发表于 10-11-2005 12:44 PM | 显示全部楼层
原帖由 jasonmun 于 10-11-2005 09:28 AM 发表
warning 警告,

initialize 后的 variables
必须给一个value,
否则程序可能会出现问题..


//This Peoject is about system banking.
#include<iostream>
#include<fstream>
#include<cstdlib>
using namespace std;


double storemoney(double);
double takeoutmoney(double);
double checking(double);
int main()
{
        int a;
        int sm;
        int tom;
        int cm;

        cout<<"ATM BANK OF EVOLUTION\n\n\n";
        cout<<"1.SAVING\n";
        cout<<"2.DRAWING\n";
        cout<<"3.CHECKING ACCOUNT\n";
        cout<<"4.Quit\n\n";
        cout<<"Please Enter A Number\n";
        cin>>a;

        if (a==1)
                storemoney(sm);
               
        else if        (a==2)
                takeoutmoney(tom);
        else if (a==3)
                checking(cm);
        else
                cout<<"Thank You\n"<<"Please Come Again\n";


        return 0;
}

//function to store money
double storemoney(double sm)
{
        int earn;
        cout<<"How much you want to store?\n";
        cin>>earn;
        cout<<"You have store "<<earn<<" in the bank\n";
        cout<<"Your balance in the account is xxx\n";
        return 0;
}

//function to take out money from bank
double takeoutmoney(double tom)
{
        int lose;
        cout<<"How much you want to take out?\n";
        cin >>lose;
        cout<<"You have take out <<lose<< from the bank";
        cout<<"Your balance in the account is xxx\n";
        return 0;
}

//function to checking account
double checking(double cm)
{
        cout<<"Your balance in the bank is xxx\n";
        return 0;
}






我的是要user enter 才会有value, 之前是没有的,可是要怎样initialized?
回复

使用道具 举报

发表于 10-11-2005 01:12 PM | 显示全部楼层
我搞不懂你的sm, tom, cm这三个parameter是用来干嘛的?
回复

使用道具 举报


ADVERTISEMENT

发表于 10-11-2005 10:35 PM | 显示全部楼层
注意你的符號, 一般上會製造很多預想不到的 bug


cout<<"You have store "<<earn<<" in the bank\n";

cout<<"You have take out <<lose<< from the bank";
回复

使用道具 举报

 楼主| 发表于 16-11-2005 11:26 PM | 显示全部楼层
小弟的这段function 有问题....
account的data 数据是100,我store 20, balance 还是100,我要的是120....

//function to store money
double storemoney(double sm)
{
        int earn;
        ifstream infile;
        int sum=0;

        infile.open("account.dat");
        if(infile)
        {

                cout<<"How much you want to store?\n";
                cin>>earn;
                cout<<"You have store "<<earn<<" in the bank\n";
                infile>>earn;
                sum=sum+earn;
                cout<<"Your balance in the account is "<<sum<<""<<endl;

                infile.close();
        }
        else
        {
                cerr<<"Unable to open the account data"<<endl;
        }

        return 0;
}
回复

使用道具 举报

 楼主| 发表于 17-11-2005 09:23 PM | 显示全部楼层
昨天的问题解决了,要谢谢雨吟
谢谢你哦....

现在小弟有几个问题,为什么我的if statement 不能这样放?
if(n<=0&&n=ch)
    cout<<"invalid input\n";

我要的是不能输入character...
请各位大大帮忙...
回复

使用道具 举报

 楼主| 发表于 18-11-2005 12:14 AM | 显示全部楼层
最新问题,以上的解决了,为什么不能够选y/n,会auto跳到okie去.....

//function to store money
double storemoney(double sm)
{
        int earn;
        ifstream infile;
        ofstream outacc;
        ofstream outfile;
        int accmoney;
        char ch;
        char confirm;

infile.open("account.dat");
        if(infile)
        {
       
        while(infile >> accmoney )
                {
                         
                        cout<<"How much you want to store?\n";
                        cin>>earn;
                        if(earn<=0&&ch)
                                {                       
                                        cout<<"Invalid Input\n";
                                        goto again;
                                }                                                       
                        else if(earn>0)
                        {
                                cout<<"You have store "<<earn<<" in the bank\n";
                                accmoney = accmoney + earn;
                                blmoney:cout<<"Your balance in the account is "<<accmoney<<""<<endl;
                        }
                        else
                        {       
                                        again:cout<<"Do You Want to Store Again?(Y/N)\n";
                                        cin>>confirm;
                                       
                                        if(confirm='y'||'Y')
                                                cout<<"okie\n";
                                        else if(confirm='n'||'N')
                                                goto blmoney;
                                        else
                                                cout<<"Invalid Input";
                                       

                        }
                }
               
                infile.close();

                outacc.open("account.dat");
                outacc<<accmoney;
                outacc.close();

                outfile.open("result.dat");
                if(!outfile)
                {
                        cerr<<"result.dat could not be opened";
                }
                else
                {
                        outfile<<"The account balance is "<<accmoney<<""<<endl;
                        outfile.close();
                }
        }
        else
        {
                cerr<<"Unable to open the account data"<<endl;
        }

        return 0;
}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 21-9-2024 01:42 PM , Processed in 0.113003 second(s), 22 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表