这是一个借贷查询系统来的

nnryzwxz 2007-04-06 09:41:23
#include "stdafx.h"
#include <iostream>
#include <stdlib.h>
#include <fstream>
#include <iomanip>

using namespace std;


int main2()// 改下名字..
{
ofstream client("clients.dat", ios::out);
if(!client){

cerr<<"File could not be opened"<<endl;
exit(1);

}

cout<<"Enter the account , name , and balance:\n"
<<"Enter end-of-file to end input:\n?";

int account;
char name[30];
float balance;

while (cin>>account>>name>>balance){


client<<account<<' '<<name<<' '<<balance<<'\n';
cout<<"?";

}
return 0;
}
enum RequestType{zb=1, cb, db, end};
int getRequest();
bool shouldDisplay(int ,double);
void outputLine(int, const char *, double);


int main(int argc, _TCHAR* argv[])
{
main2(); //在这里调用上个程序..
ifstream client("clients.dat", ios::in);
if(!client){
cerr<<"File could not be opened\n";
exit(1);
}

int account ;
char name[30];
double balance;
int request;

cout<<"Enter request\n"
<<"1-List accounts with zero balbace\n"
<<"2-List accounts with credit balbace\n"
<<"3-List accounts with debit balbace\n"
<<"4-End of run";
request=getRequest();

while (request!=end){
switch(request){
case zb:
cout<<"\nAccounts with zb;\n";
break;
case cb:
cout<<"\nAccounts with cb;\n";
break;
case db:
cout<<"\nAccounts with db;\n";
break;
}

client>>account>>name>>balance;

while (!client.eof()){
if(shouldDisplay(request, balance))
outputLine(account, name , balance);
client>>account>>name>>balance;
}

client.clear();
client.seekg(0);
request=getRequest();
}

cout<<"End of run."<<endl;
return 0;
}


int getRequest(){
int request;
do{
cout<<"\n?";
cin>>request;
}while(request<zb&& request>end);

return request;

}

bool shouldDisplay(int type, double balance){

if(type==cb && balance<0)
return true ;
if(type==db && balance>0)
return true;
if(type==zb && balance==0)
return true;
return false ;


}


void outputLine(int acct, const char *name, double bal)
{
cout<<setiosflags(ios::left)<<setw(10)<<acct
<<setw(13)<<name<<setw(17)<<setprecision(2)
<<resetiosflags(ios::left)
<<setiosflags(ios::fixed|ios ::showpoint)
<<bal<<'\n';
在生成的时候没有错误和警告但是在运行的时候缺陷入了死循环,我真的找不出到底错在了那里,谢谢大家了.头都弄大了

}

...全文
662 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
不想低调 2007-04-07
  • 打赏
  • 举报
回复
mark
laiwusheng 2007-04-06
  • 打赏
  • 举报
回复
while (request!=end){//request在什么情况下等于end?

65,187

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧