我的银行计划提示没有返回结果

时间:2017-09-28 04:53:54

标签: c

我正在制作一个带有功能的银行程序.1名为displaymenu,产生菜单d(存款),w(提取),b(支票余额)和 q(退出).2nd函数是getdeposit,它接受余额作为参数并询问用户他们想要存入的金额然后添加金额 平衡并将其返回到main函数.3rd getwithdrawal相同的参数(余额和减去金额和返回结果) 最后一个displaybalance它还接受balance作为参数并显示currentbalance.then使用switch语句来选择哪个函数 如果他们选择退出回应而不是基于选择进行选择。我正在制作我的转换语句,但我失去了什么 添加我的程序显示菜单,但当我选择一个选项时,它会显示我选择并坐在那里的字母 问我的选择。有人可以查看我的代码并指出我正确的方向吗?

      #include <stdio.h>

    char displaymenu();
    float getdeposit(float amount,float balance);
    float  getwithdrawal(float amount,float balance);
    float displaybalance(float balance);


        int main()
        {

          char  choice;
          float deposit;
          float withdrawal;
          float balance;
          float amount;

          choice=displaymenu();
          deposit=getdeposit(amount,balance);
          withdrawal=getwithdrawal(amount,balance);
          balance=displaybalance(balance); 




           switch (choice)
          {

             case 'd':case 'D':
                printf("How much would you like to deposit?");
                break;

             case 'w':case 'W':
                printf("How much would you like to withdraw?");
                break;

             case 'b':case 'B':
                printf("Checking your account balance");
                break;

              case 'q':case 'Q':
                printf("Quit");
                break;

                default:
                printf("Invalid Choice");
          }

         return 0;
       }

         char displaymenu()
         {
            char choice;



            printf("Welcome to Federal Credit Union!\n");
            printf("Please select from the following menu\n");
            printf("d. Make a deposit\n");
            printf("w. Make a withdrawal\n");
            printf("b. check balance\n");
            printf("q. Quit\n");
            scanf ("%c",&choice);
            return choice;


              }


             float getdeposit(float amount,float balance)
            {

                float deposit;
                deposit=amount+balance;
                scanf ("%f",&deposit);
                return deposit; 

            }

             float  getwithdrawal(float amount,float balance)
            {

                float withdrawal;   
                withdrawal=amount-balance;
                scanf ("%f",&withdrawal);
                return withdrawal;  
            }

             float displaybalance(float balance)
            {

                printf("Your balance is %.2f\n",&balance);

            }

1 个答案:

答案 0 :(得分:0)

我对您的代码进行了一些更改,现在它运行得很好。

#include <stdio.h>
char displaymenu();
float getdeposit(float amount,float balance);
float  getwithdrawal(float amount,float balance);
float displaybalance(float balance);


    int main()
    {

      char  choice;
      float deposit;
      float withdrawal;
      float balance;
      float amount;

      choice=displaymenu();
                 switch (choice)
      {

         case 'd':case 'D':
            printf("How much would you like to deposit?\n");
            deposit=getdeposit(amount,balance);
            break;

         case 'w':case 'W':
            printf("How much would you like to withdraw?\n");
            withdrawal=getwithdrawal(amount,balance);
            break;

         case 'b':case 'B':
            printf("Checking your account balance\n");
            balance=displaybalance(balance);
            break;

          case 'q':case 'Q':
            printf("Quit\n");
            break;

            default:
            printf("Invalid Choice\n");
      }
     return 0;
   }

     char displaymenu()
     {
        char choice;



        printf("Welcome to Federal Credit Union!\n");
        printf("Please select from the following menu\n");
        printf("d. Make a deposit\n");
        printf("w. Make a withdrawal\n");
        printf("b. check balance\n");
        printf("q. Quit\n");
        scanf ("%c",&choice);
        return choice;


          }


         float getdeposit(float amount,float balance)
        {

            float deposit;
            deposit=amount+balance;
            scanf ("%f",&deposit);
            return deposit;

        }

         float  getwithdrawal(float amount,float balance)
        {

            float withdrawal;
            withdrawal=amount-balance;
            scanf ("%f",&withdrawal);
            return withdrawal;
        }

         float displaybalance(float balance)
        {

            printf("Your balance is %.2f\n",&balance);

        }