| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2235 人关注过本帖
标题:用了gerchar(),屏幕还是一闪而过怎么办(自动取款机的程序)
只看楼主 加入收藏
Angel乖乖
Rank: 1
等 级:新手上路
帖 子:70
专家分:3
注 册:2011-5-14
收藏
得分:0 
回复 17楼 hellovfp
这个程序还是有问题
这儿应该改一下
int ACCOUNT::chaxun(unsigned long id,unsigned int pw)
 {
     if(check(id,pw))
         return ballance;---------- 改为return error
     else
     {
         cout << "here" << endl;
         return error;-----------   改为 return ballance   
     }
 }
这样就好了。
要不然程序刚好是反的
很谢谢你呀!!
辛苦了。。
2011-11-21 19:56
m1c2f4843
Rank: 1
等 级:新手上路
帖 子:27
专家分:4
注 册:2010-7-30
收藏
得分:0 
设断点 慢慢调 自己多试几次就会了
2011-11-21 21:58
lqsh
Rank: 2
来 自:山东济南
等 级:论坛游民
帖 子:26
专家分:58
注 册:2011-8-29
收藏
得分:0 
程序代码:
#include<iostream>

 #include<string.h>

 #define error 0

 #define succee 1

 class ACCOUNT

 {

 private:
     unsigned long ID;
     unsigned int password;
     char name[20];
     int ballance;

 public:
     ACCOUNT(unsigned long id,unsigned int pw,char *n,int a);

    int cunkuan(unsigned long id,unsigned int pw,int a);
     int qukuan(unsigned long id,unsigned int pw,int a);
     int chaxun(unsigned long id,unsigned int pw);
     int check(unsigned long id,unsigned int pw);

 };

 ACCOUNT::ACCOUNT(unsigned long id,unsigned int pw,char *n,int a)

 {
     ID=id;password=pw;
     strcpy(name, n);
     ballance=a;

}

 int ACCOUNT::cunkuan(unsigned long id,unsigned int pw,int a)

 {
     if(!check(pw,id))
         return error;
     else
     {
         ballance+=a;
         return succee;
         cout<<"您的余额为:"<<ballance<<endl;
     }

 }

 int ACCOUNT::qukuan(unsigned long id,unsigned int pw,int a)

 {
     if(!check(pw,id))
         return error;
     else
     {if(ballance<a)
     cout<<"您的余额已不足!"<<endl;
     else
         ballance-=a;
     }

 }

 int ACCOUNT::chaxun(unsigned long id,unsigned int pw)

 {
     if(check(pw,id))
         return ballance;
     else
         return error;

 }

 int ACCOUNT::check(unsigned long id,unsigned int pw)

 {
     if(id==ID&&pw==password)
         return succee;
     else
         return error;

 }

 void main()

 {
     ACCOUNT A(1,1,"Angel",500);
     int c;
     unsigned long id;
     unsigned int pw;
     int a;
     cout<<"欢迎使用"<<endl;
     cout<<"-----------------------"<<endl;
     cout<<"<1>存款\n<2>取款\n<3>查询余额\n<4>结束"<<endl;
     cout<<"请选择:"<<endl;
     cin>>c;
     getchar();
     while(c!=4)
     {
         switch(c)
         {
         case 1:
             cout<<"请输入账号:"<<endl;
             cin>>id;
             cout<<"请输入密码:"<<endl;
             cin>>pw;
             cout<<"请输入存款余额:"<<endl;
             cin>>a;
             if(A.cunkuan(id,pw,a))
             {
                 cout<<"操作成功,您目前的余额为 "<<endl;
      
                cout<<A.chaxun(id,pw)<<""<<endl;
             }
             else
                 cout<<"操作失败!"<<endl;
             getchar();
             break;
         case 2:
             cout<<"请输入账号:"<<endl;
             cin>>id;
             cout<<"请输入密码:"<<endl;
             cin>>pw;
             cout<<"请选择取款余额:\t<1>100\t<2>200\t<3>500\t<4>1000"<<endl;
             cin>>a;
             if(A.qukuan(id,pw,a))
             {
                 cout<<"操作成功,您目前的余额为 "<<endl;
                 cout<<A.chaxun(id,pw)<<""<<endl;
             }
             else
                 cout<<"操作失败!"<<endl;
             getchar();
             break;
         case 3:
             cout<<"请输入账号:"<<endl;
             cin>>id;
             cout<<"请输入密码:"<<endl;
             cin>>pw;
             if(A.check(id,pw))
                 cout<<"您目前的余额为 "<<endl;
             cout<<A.chaxun(id,pw)<<""<<endl;
             getchar();

            break;
         }
         cout<<"请继续选择"<<endl;
         cout<<"<1>存款\n<2>取款\n<3>查询余额\n<4>结束"<<endl;
          cin>>c;
     }
     cout<<"谢谢使用!"<<endl;
     getchar();

}

自己调试一下程序,很多程序很容易改正,你的程序基本上正确啦。
2011-11-22 00:11
lqsh
Rank: 2
来 自:山东济南
等 级:论坛游民
帖 子:26
专家分:58
注 册:2011-8-29
收藏
得分:0 
调用check()函数判断上逻辑有问题,已帮你改正。另外像while(C!=4)写错太不应该,学会debug自己的code
2011-11-22 00:15
Angel乖乖
Rank: 1
等 级:新手上路
帖 子:70
专家分:3
注 册:2011-5-14
收藏
得分:0 
回复 23楼 lqsh
你的虽然逻辑好像对了
但执行起来错误很多  我用VC2008有60多个
我现在的问题是 输入错误的密码竟然能执行
我贴下代码
程序代码:
#include <iostream>

 #include <string>


 #define error 0

 #define succee 1

 using namespace std;

 class ACCOUNT

 {

 private:
     unsigned long ID;
     unsigned int password;
     string name;
     int ballance;

 public:
     ACCOUNT(unsigned long id,unsigned int pw,string n,int a);

    int cunkuan(unsigned long id,unsigned int pw,int a);
     int qukuan(unsigned long id,unsigned int pw,int a);
     int chaxun(unsigned long id,unsigned int pw);
     int check(unsigned long id,unsigned int pw);

 };

 ACCOUNT::ACCOUNT(unsigned long id,unsigned int pw,string n,int a)

 {
     ID=id;
     password=pw;
     name = n;
     ballance=a;

}

 int ACCOUNT::cunkuan(unsigned long id,unsigned int pw,int a)

 {
     if(check(id,pw))
         return error;
     else
     {
         ballance+=a;
         return succee;
         cout<<"您的余额为:"<<ballance<<endl;
     }

 }

 int ACCOUNT::qukuan(unsigned long id,unsigned int pw,int a)

 {
     switch(a)
     {
     case 1:a=100;
              break;
    case 2:a=200;
              break;
     case 3:a=500;
              break;
    case 4:a=1000;
        break;}
             

     if(check(id,pw))
      return error;
   
     else
     {
         if(ballance<a)
             cout<<"您的余额已不足!"<<endl;
       
         else
             ballance-=a;
         return ballance;
     }
   

 }

 int ACCOUNT::chaxun(unsigned long id,unsigned int pw)

 {
   
   
     if(check(id,pw))
         return error;
     else
         return ballance;

 }

 int ACCOUNT::check(unsigned long id,unsigned int pw)

 {
     if(id==ID&&pw==password)
         return succee;
     else
         return error;

 }

 int main()

 {
     ACCOUNT A(1005170228,123456,"Angel",500);
     int c;
     unsigned long id;
     unsigned int pw;
     int a;
     cout<<"欢迎使用"<<endl;
     cout<<"-----------------------"<<endl;
     cout<<"<1>存款\n<2>取款\n<3>查询余额\n<4>结束"<<endl;
     cout<<"请选择:"<<endl;

     cin>>c;
     getchar();
     while(c!=4)
     {
         switch(c)
         {
         case 1:
             cout<<"请输入账号:"<<endl;
             cin>>id;
             cout<<"请输入密码:"<<endl;
             cin>>pw;
             cout<<"请输入存款金额:"<<endl;
             cin>>a;
             if(A.cunkuan(id,pw,a))
             {
                 cout<<"操作成功,您目前的余额为 "<<endl;

                cout<<A.chaxun(id,pw)<<""<<endl;
             }
             else
                 cout<<"操作失败!"<<endl;
             getchar();
             break;
         case 2:
             cout<<"请输入账号:"<<endl;
             cin>>id;
             cout<<"请输入密码:"<<endl;
             cin>>pw;
             cout<<"请选择取款余额:\t<1>100\t<2>200\t<3>500\t<4>1000"<<endl;
             cin>>a;
             if(A.qukuan(id,pw,a))
             {
                 cout<<"操作成功,您目前的余额为 "<<endl;
                 cout<<A.chaxun(id,pw)<<""<<endl;
             }
             else
                 cout<<"操作失败!"<<endl;
             getchar();
             break;
         case 3:
             cout<<"请输入账号:"<<endl;
             cin>>id;
             cout<<"请输入密码:"<<endl;
             cin>>pw;
             if(A.check(id,pw))
                 cout<<"您目前的余额为 "<<endl;
             cout<<A.chaxun(id,pw)<<""<<endl;
             getchar();

            break;
         }
         cout<<"请继续选择"<<endl;
         cout<<"<1>存款\n<2>取款\n<3>查询余额\n<4>结束"<<endl;
         cin>>c;
     }
     cout<<"谢谢使用!"<<endl;
     getchar();
     getchar();
     return 0;

 }
当我改了逻辑之后 完全不能执行。。。
2011-11-22 08:24
hellovfp
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:禁止访问
威 望:30
帖 子:2976
专家分:7697
注 册:2009-7-21
收藏
得分:0 
程序代码:
#include <iostream>
#include <string>
#include <cstdio>

#define error 0
#define succee 1
using namespace std;
class ACCOUNT
{
private:
    unsigned long ID;
    unsigned int password;
    string name;
    int ballance;
public:
    ACCOUNT(unsigned long id,unsigned int pw,string n,int a);

    int cunkuan(unsigned long id,unsigned int pw,int a);
    int qukuan(unsigned long id,unsigned int pw,int a);
    int chaxun(unsigned long id,unsigned int pw);
    int check(unsigned long id,unsigned int pw);
};
ACCOUNT::ACCOUNT(unsigned long id,unsigned int pw,string n,int a)
{
    ID=id;
    password=pw;
    name = n;
    ballance=a;

}
int ACCOUNT::cunkuan(unsigned long id,unsigned int pw,int a)
{
    if(!check(id,pw))
        return error;
    else
    {
        ballance+=a;
        return succee;
        cout<<"您的余额为:"<<ballance<<endl;
    }
}
int ACCOUNT::qukuan(unsigned long id,unsigned int pw,int a)
{
    switch(a)
    {
    case 1:
        a=100;
        break;
    case 2:
        a=200;
        break;
    case 3:
        a=500;
        break;
    case 4:
        a=1000;
        break;
    }


    if(!check(id,pw))
        return error;

    else
    {
        if(ballance<a)
            cout<<"您的余额已不足!"<<endl;

        else
            ballance-=a;
        return ballance;
    }

}
int ACCOUNT::chaxun(unsigned long id,unsigned int pw)
{
    if(!check(id,pw))
        return error;
    else
        return ballance;
}
int ACCOUNT::check(unsigned long id,unsigned int pw)
{
    if(id==ID&&pw==password)
        return succee;
    else
        return error;
}
int main()
{
    ACCOUNT A(1005170228,123456,"Angel",500);
    int c;
    unsigned long id;
    unsigned int pw;
    int a;
    cout<<"欢迎使用"<<endl;
    cout<<"-----------------------"<<endl;
    cout<<"<1>存款\n<2>取款\n<3>查询余额\n<4>结束"<<endl;
    cout<<"请选择:"<<endl;

    cin>>c;
    getchar();
    while(c!=4)
    {
        switch(c)
        {
        case 1:
            cout<<"请输入账号:"<<endl;
            cin>>id;
            cout<<"请输入密码:"<<endl;
            cin>>pw;
            cout<<"请输入存款金额:"<<endl;
            cin>>a;
            if(A.cunkuan(id,pw,a))
            {
                cout<<"操作成功,您目前的余额为 "<<endl;

                cout<<A.chaxun(id,pw)<<""<<endl;
            }
            else
                cout<<"操作失败!"<<endl;
            getchar();
            break;
        case 2:
            cout<<"请输入账号:"<<endl;
            cin>>id;
            cout<<"请输入密码:"<<endl;
            cin>>pw;
            cout<<"请选择取款余额:\t<1>100\t<2>200\t<3>500\t<4>1000"<<endl;
            cin>>a;
            if(A.qukuan(id,pw,a))
            {
                cout<<"操作成功,您目前的余额为 "<<endl;
                cout<<A.chaxun(id,pw)<<""<<endl;
            }
            else
                cout<<"操作失败!"<<endl;
            getchar();
            break;
        case 3:
            cout<<"请输入账号:"<<endl;
            cin>>id;
            cout<<"请输入密码:"<<endl;
            cin>>pw;
            if(A.check(id,pw))
            {
                cout<<"您目前的余额为 "<<endl;
                cout<<A.chaxun(id,pw)<<""<<endl;
                getchar();
            }
            else
            {
                cout << "★账号或是密码错误!★" << endl;
            }
            break;
        }
        cout<<"-----------------------"<<endl;
        cout<<"请继续选择"<<endl;
        cout<<"<1>存款\n<2>取款\n<3>查询余额\n<4>结束"<<endl;
        cin>>c;
    }
    cout<<"谢谢使用!"<<endl;
    getchar();
    getchar();
    return 0;
}
不过,C++程序真的不是这么写的。

我们都在路上。。。。。
2011-11-22 14:02
Angel乖乖
Rank: 1
等 级:新手上路
帖 子:70
专家分:3
注 册:2011-5-14
收藏
得分:0 
回复 26楼 hellovfp
太谢谢你了!!
其实我自己改过,都没改对。。。
那怎样写C++啊??
2011-11-22 19:15
Angel乖乖
Rank: 1
等 级:新手上路
帖 子:70
专家分:3
注 册:2011-5-14
收藏
得分:0 
最后一点

   
程序代码:
     if(!check(id,pw))
      return error;
   
     else
     {
         if(ballance<a)
         {
             cout<<"您的余额已不足!"<<endl;
         return error;                         //加上这句就完美了,要不就出现小小的错误
         }
         else
             ballance-=a;
         return ballance;
     }
     
  
2011-11-22 23:22
Angel乖乖
Rank: 1
等 级:新手上路
帖 子:70
专家分:3
注 册:2011-5-14
收藏
得分:0 
最后发一遍完整代码
程序代码:
#include

 #include 


 #define error 0

 #define succee 1

 using namespace std;

 class ACCOUNT

 {

 private:
     unsigned long ID;
     unsigned int password;
     string name;
     int ballance;

 public:
     ACCOUNT(unsigned long id,unsigned int pw,string n,int a);

    int cunkuan(unsigned long id,unsigned int pw,int a);
     int qukuan(unsigned long id,unsigned int pw,int a);
     int chaxun(unsigned long id,unsigned int pw);
     int check(unsigned long id,unsigned int pw);

 };

 ACCOUNT::ACCOUNT(unsigned long id,unsigned int pw,string n,int a)

 {
     ID=id;
     password=pw;
     name = n;
     ballance=a;

}

 int ACCOUNT::cunkuan(unsigned long id,unsigned int pw,int a)

 {
     if(!check(id,pw))
         return error;
     else
     {
         ballance+=a;
         return succee;
         cout<<"您的余额为:"<
终于完整喽
撒花撒花。。。


[ 本帖最后由 Angel乖乖 于 2011-11-22 23:29 编辑 ]
2011-11-22 23:24
Angel乖乖
Rank: 1
等 级:新手上路
帖 子:70
专家分:3
注 册:2011-5-14
收藏
得分:0 
谢谢大家。。。
2011-11-22 23:31
快速回复:用了gerchar(),屏幕还是一闪而过怎么办(自动取款机的程序)
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.048794 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved