Dは入金、Cは出金としています。
現在、FOR文を使い、4回繰り返ししています。
まず最初に1000プラスしたとして、次にもう一度1000プラスしたいのですが、入力しても記憶されていないため、再び表示されるのは1000になってしまいます。
この問題と、D,C以外を入力された場合、Please enter C or D: から再開にしたいです。
今回 IF 文を使用しました。間違っていたら他の文でやり直します。
よろしくお願いします。
#include <stdio.h> FILE * fp; int chacking(void); int main(void) { printf("Welcome to Ron's Checking Account Tracer Progtam\n"); printf("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n"); int i; fp = fopen("csis.txt","w"); for (i =1; i <= 4; ++i) chacking(); fclose(fp); return 0; } int chacking(void) { double amount = 0, balance = 0; char value; int i; for(i = 0; i < 4; i++) { printf("Please enter C or D: "); scanf("%c",&value); if(value == 'D' || value == 'd') { printf("How much money do you want to deposit?: "); scanf("%lf",&amount); balance = balance + amount; printf("The transaction is a: %c and the amount is: %.2lf\n",value,amount); printf("The balance is: %.2lf\n",amount); } else if(value == 'C' || value == 'C') { printf("How much money do you want to withdraw?: "); scanf("%lf",&amount); balance = balance - amount; printf("The transaction is a: %c and the amount is: %.2lf\n",value,amount); printf("The balance is: %.2lf\n",amount); } } return 0; }
回答1件
あなたの回答
tips
プレビュー