问题及代码:
/*
* Copyright (c) 2014, 烟台大学计算机学院
* All rights reserved.
* 文件名称:yinhang.cpp
* 作 者:夏焕哲
* 完成日期:2014 年 11 月 15 日
* 版 本 号:v1.0
* 问题描述:建立一个银行存取转业务程序。
* 输入描述: 输入一个密码和服务项目。
* 程序输出: 相应结果。
*/
#include <iostream>
using namespace std;
const int PASSWORD=123456;
int password ;
int sum=1000000;
int take;
int give;
int bring;//give:转账。take:取款。bring:存款。sum:一开始就在银行中的钱。
int main()
{
int number;
cout<<".....................夏氏银行欢迎您......................"<<endl;;
cout<<"请输入密码:";
cin>>password;
do
{
if (password==PASSWORD)
{
cout<<"您可以办理下面的业务:"<<endl;
cout<<"1.查询"<<endl;
cout<<"2.取款"<<endl;
cout<<"3.存款"<<endl;
cout<<"4.转账"<<endl;
cout<<"0.退出"<<endl;
cout<<"请输入(0-4):"<<endl;
do
{
cin>>number;
switch (number)
{
case 1:
cout<<"您的余额还有"<<sum<<endl;;
continue;
case 2:
cout<<"请输入取款金额:";
cin>>take;
sum=sum-take;
continue;
case 3:
cout<<"请输入你要存入的金额";
cin>>bring;
sum=sum+bring;
continue;
case 4:
cout<<"请输入你要转账的金额";
cin>>give;
sum=sum-give;
continue;
case 0:
cout<<"谢谢,欢迎下次光临。";
break;
default:
cout<<"输入错误,不要着急。"<<endl;;
continue;
}
if (number==0)break;
}
while (1);
}
else
{
cout<<"密码错误请重新输入:";
cin>>password;
}
if (number==0)break;
}
while (1);
}
运行结果:
心得体会:学的全用上,好有成就感。