C程序复制printf语句

时间:2018-09-14 06:41:44

标签: c gcc

在我最近的一些代码中,一旦编译并执行程序,该程序将重复printf()条语句,可能会跳过scanf()。 代码如下:

#include <stdio.h>
#include <stdlib.h>

 int main()
 {
 float Tran, Acc = 100.00;
 char a = a,b = b;
 printf("Your Account has $%.2f in it currently\n",Acc);
 printf("Would you like to make a transaction?(Y or N):\n");
 scanf("%c", &a);

 while (a == 'Y') {
     printf("Withdrawal or Deposit?(W or D):\n");
     scanf("%c", &b);
     if (b == 'W'){
         printf("How much would you like to withdrawal?:\n");
         scanf("%f",&Tran);
         Acc = Acc - Tran;
         printf("Your new account balance is %.2f\n Would you like to make another Transaction?(Y or N)\n",Acc);
         scanf("%c", &a);
     }
    else if (b == 'D'){
        printf("How much would you like to deposit?\n");
         scanf("%f",&Tran);
         Acc = Acc + Tran;
         printf("Your new account balance is %.2f\n Would you like to make another Transaction?(Y or N)\n",Acc);
         scanf("%c", &a);
    }
 }
 return 0; 

执行后的返回值为

enter image description here

该代码也应该循环,但也不能实现。我仍处于入门阶段,对此我还是很陌生,谢谢您能提供的任何帮助

0 个答案:

没有答案