一个无聊的自动提款机程序

来源:互联网 发布:程序员思维导图 编辑:程序博客网 时间:2024/04/30 22:59
/* * 自动提款机程序,他会问用户很多的yes/no的问题 *  * atm.sh *  * while true * do  * do_a_transaction # run a program *      if play_again    # run our program *then     *     continue     # if "y" loop back * fi *break            # if "n" break * done * * 这个银行脚本程序将程序的各个组件组合起来 * 1.第一个称为do_a_transaction的程序,完成ATM的工作 * 2.第二个组件play_again,从用户得到回答 *  * */ /*  * PLAY_AGAIN.C  * 功能:实现组件2  *   * 对用户显示提示问题  * 接受输入  * 如果是y,返回0  * 如果是n,返回1  *  */  #include <stdio.h>  #include <termios.h>  #define QUESTION "Do you want another transaction"  int get_response(char *);    int main(){  int response;response = get_response(QUESTION);return response;  }  int get_response(char *question){  printf("%s(y/n)?",question);while(1){//循环读取用户的输入,指导用户输入ynYN//switch(getchar()){   case 'y':   case 'Y':return 0;   case 'n':   case 'N':   case EOF:return 1;}}    }

原创粉丝点击