账目簿结算

/*********************************************************
 * From C PROGRAMMING: A MODERN APPROACH, by K. N. King  *
 * Copyright (c) 1996 W. W. Norton & Company, Inc.       *
 * All rights reserved.                                  *
 * This program may be freely distributed for class use, *
 * provided that this copyright notice is retained.      *
 *********************************************************/
/* checking.c (Chapter 6, page 101) */
/* Balances a checkbook */
/*账目簿结算*/
#include <stdio.h>
main()
{
  int cmd;
  float balance = 0.0, credit, debit;
  printf("*** ACME checkbook-balancing program ***\n");
  printf("Commands: 0=clear, 1=credit, 2=debit, ");
  printf("3=balance, 4=exit\n\n");
  for (;;) {
    printf("Enter command: ");
    scanf("%d", &cmd);
    switch (cmd) {
      case 0:
        balance = 0.0;  //刷新账户余额
        break; //跳出整个循环
      case 1:
        printf("Enter amount of credit: ");
        scanf("%f", &credit);
        balance += credit; //balance=balance+credit 往账户上存钱
  printf("balance=%f\n",balance);
        break;
      case 2:
        printf("Enter amount of debit: ");
        scanf("%f", &debit);
        balance -= debit;  //balance=balance-debit 从账户上取钱
        break;
      case 3:
        printf("Current balance: $%.2f\n", balance); //显示当前的余额
        break;
      case 4:       
        return 0;   //退出程序
      default:
        printf("Commands: 0=clear, 1=credit, 2=debit, ");
        printf("3=balance, 4=exit\n\n");
        break;
    }
  }
}

你可能感兴趣的:(职场,休闲,结算,账目)