这是一个借贷查询系统来的
#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';
在生成的时候没有错误和警告但是在运行的时候缺陷入了死循环,我真的找不出到底错在了那里,谢谢大家了.头都弄大了
}