5 设计一个简单的ATM界面程序

mac2022-06-30  26

5.1概述

设计一个简单的模拟自动提款机ATM界面的程序,实现用户登录及取款等功能。

5.2 需求分析

模拟自动取款机ATN界面,有常用的功能。 主要功能包括:用户输入密码登录主界面、取款功能、取款后显示取款金额和剩余金额、推出功能等

5.3 设计思路

先要用户输入密码,密码不正确并输入次数小于三次将提示重新输入,否则退出界面;密码正确进入取款界面,执行取款功能,然后显示取款金额和剩余金额,最后退出程序。

5.4 程序

#include <iostream> #include<stdio.h> #include<stdlib.h> using namespace std; int main() {while(1) { char Key,CMoney; int password1=1,password,i=1,a=1000; do { system("cls"); printf("***************************\n"); printf("* please select key: *\n"); printf("* 1.password: *\n"); printf("* 2.get money: *\n"); printf("* 3. return: *\n"); printf("***************************\n"); Key=getchar(); } while(Key!='1'&&Key!='2'&&Key!='3'); switch(Key) { case'1': system("cls"); do { i++; printf("please input password "); scanf("%d",&password); if(password!=password1) { if(i>3) { printf("wrong!please any key to exit"); getchar(); exit(0); } else puts("wrong,try again"); } }while(password1!=password&&i<=3); case'2': do { system("cls"); if(password!=password1) { printf("please logging in,please any key to continue..."); getchar(); break; } else { printf("*************\n"); printf("* please select: *\n"); printf("* 1.100: *\n"); printf("* 2.200: *\n"); printf("* 3.300: *\n"); printf("* 4.return *\n"); printf("*************\n"); CMoney=getchar(); } }while(CMoney!='1'&&CMoney!='2'&&CMoney!='3'); switch(CMoney) { case'1': system("cls"); a=a-100; printf("* your credit money is 100,thank you * \n"); printf("* the balance is %d \n",a); printf("please any key to return... \n"); printf("*************\n"); getchar(); break; case'2': system("cls"); a=a-200; printf("* your credit money is 200,thank you * \n"); printf("* the balance is %d \n",a); printf("please any key to return... \n"); printf("*************\n"); getchar(); break; case'3': system("cls"); a=a-300; printf("* your credit money is 300,thank you * \n"); printf("* the balance is %d \n",a); printf("please any key to return... \n"); printf("*************\n"); getchar(); break; case'4': break; } break; case'3': printf("*************\n"); printf("* thank you for your using: *\n"); printf("* goodbye *\n"); printf("*************\n"); getchar(); break; } break; } }
最新回复(0)