zoukankan      html  css  js  c++  java
  • iOS开发—c语言 ATM取款机(一)

    #include <stdio.h>
    #include <stdlib.h>
    int main(int argc, const char * argv[]) {
        int password = 123;//声明一个变量 不会分配内存空间 使用的时候就分配
        int inputPassword = 0;//接收用户输入的密码
        int wrongTime = 0;//记录错误的数据
        int choice = 0;//记录用户的选择操作
        float money = 10000;//总金额
        //提示用户输入密码
    while(1){
            printf("请输入密码:");
            scanf("%d",&inputPassword);
            
            //判断密码是否相同
            if(password==inputPassword){
                //接下来的事情
                break;}//跳出本层循环do while,而不是简单地跳出if语句
            else{
                printf("密码错误");
                wrongTime++;
                
                //判断错误的次数
                if (wrongTime == 3)
    {
    //退出程序 exit(EXIT_SUCCESS);//可从<stdlib.h>中获取 直接结束程序 } } } while (1){ //提示用户选择相关的操作 printf("******************** "); printf("*****请选择操作******* "); printf("1.取款 "); printf("2.查询 "); printf("3.更改密码 "); printf("4.退出 "); printf("******************** "); //接收用户选择 scanf("%d",&choice);// 2被拿走,此时缓存中为2' ' switch (choice) { case 1: //取款 break; case 2: //查询余额 printf("当前余额:%f",money); //提示用户是否继续操作 printf("是否继续(y/n):"); getchar();//将上述输入的' '拿走,即从缓存中取出 char c =getchar();//等待用户输入字符 if(c == 'n'){ printf("感谢使用 再见!"); exit(EXIT_SUCCESS); } break; case 3: //更改密码 break; case 4: //退出 exit(EXIT_SUCCESS); break; default: break; } } return 0; }

    个人收获 :开发软件写代码时不需要一开始就定义好全部变量,先思考第一步干什么,一步一步写,写到需要变量的时候再去定义,解决开发软件编码时无从下手的问题

  • 相关阅读:
    hdu1556 Color the ball
    HDU
    《解读window核心编程》 之 字符和字符串处理方式
    WebService之CXF注解之四(測试类)
    gdal以GA_Update方式打开jpg文件的做法
    贪吃蛇源代码分析
    极光消息推送服务器端开发实现推送(上)
    2014,为了梦想宁愿破釜沉舟
    小强的HTML5移动开发之路(37)——jqMobi快速入门
    你可能不知道的5种 CSS 和 JS 的交互方式
  • 原文地址:https://www.cnblogs.com/kinghyt/p/9960878.html
Copyright © 2011-2022 走看看