2017-09-28 7 views
-1

이것은 표준 은행 계좌 프로그램입니다. 입금, 출금 및 조회 자금 허용. 나는 자신의 선택에 따라 switch 문 안에 함수를 입력하는 프로그램을 만드는 데 문제가있다. 다음은이 코드의 출력입니다. CodeOutput. 나는 내가 잘못한 곳을 가리킬 수만 있다면 누군가 나를 위해 코드를 작성하라고 요구하는 것이 아닙니다.C가 두 기능을 결합합니다.

#include <stdio.h> 

float getDeposit(float currentBalance); 
float getWithdrawal(float currentBalance); 
float displayBalance(float currentBalance); 
char displayMenu(); 

int main() 
{ 


    float currentBalance=200,newBalanceDep,newBalanceWith; 
    char choice; 
    choice = displayMenu(); 


     switch (choice) 
    { 

     case 'D': case 'd': 
      newBalanceDep=getDeposit(currentBalance); 
      break; 
     case 'W': case 'w': 
      newBalanceWith=getWithdrawal(currentBalance); 
      break; 
     case 'B': case 'b': 
      displayBalance(currentBalance); 
      break; 
     case 'Q': case 'q': 

      printf("Thank you!"); 
      break; 
     default: 
      printf("Invalid choice."); 
      break; 

    } 

    return 0; 
} 

char displayMenu() 

{ 
    char choice; 

    printf("Welcome to HFC 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 your account balance \n"); 
    printf("Q: To quit \n"); 

    scanf("\n%c",choice); 

    return choice; 

} 

float getDeposit(float currentBalance) 
{ 
    float depositAmount; 
    float newBalanceDep; 



    printf("Enter amount you would like to deposit: /n"); 
    scanf("%f",&depositAmount); 

    if(depositAmount>0) 
    { 
     newBalanceDep=depositAmount+currentBalance; 
    } 

    return newBalanceDep; 
} 

float getWithdrawal(float currentBalance) 
{ 
    float withdrawalAmount; 
    float newBalanceWith; 

    printf("Enter amount you would like to withdrawal: /n"); 
    scanf("%f",&withdrawalAmount); 

    if(withdrawalAmount>currentBalance) 
    { 
     printf("Insufficient Funds. Try again."); 
     printf("Enter amount you would like to withdrawal: /n"); 
     scanf("%f",&withdrawalAmount); 

    } 
    else if(withdrawalAmount<=currentBalance) 
    { 
     newBalanceWith=withdrawalAmount+currentBalance; 
    } 

    return newBalanceWith; 
} 

float displayBalance(float currentBalance) 

{ 
    printf("Your current balance is %.2f",currentBalance); 

} 
+0

출력을 이미지 대신 텍스트로 게시하십시오. –

+0

유용한 정보를 제공해주십시오. a) 그림이 아닌 b) 외부 링크가 아닙니다. 나는. 출력을 텍스트로 포함 시키려면 질문을 편집하십시오. 또한 출력에 대해 마음에 들지 않는 것을 설명하십시오. [ask]와 [mcve]를 읽는 것이 도움이 될 수 있습니다. – Yunnosch

+0

그게 내가 터미널에 들어오는 출력입니다. – Jaruto

답변

2

당신은 scanf하지 choice&choice을 통과해야합니다.

char choice; /*...*/; scanf("\n%c",choice); // --->  
//         v---- add 
char choice; /*...*/; scanf("\n%c",&choice);` 

합격 choice은 정의되지 않은 동작입니다.

좋은 컴파일러가 경고를 보내야합니다.

+0

dev-C++를 사용하고 있는데 사용자 선택에 따라 스위치 명령문에 함수를 입력하지 않아도된다는 경고가 표시되지 않습니다. – Jaruto

+0

@Jarute 내 제안을 사용하면됩니다. – PSkocik

+1

오 주소 연산자 gotcha 나는 모든 일을 읽지 못했습니다 내가 스크램블에있어 덕분에 작동합니다 – Jaruto