关于c的基础小问题,希望大家帮忙下

来源:百度知道 编辑:UC知道 时间:2024/05/02 09:12:20
Wirte a program to help balance your bank account.The program will read your initial balance and each transaction.The transaction is either withdrawal or deposit.It will print the new balance after each transaction.Negative balance is not allowed.At the end of the session,the starting and final balances should be printed along with a count of number of withdrawals and deposits processed.

We can use the following simple code'W',"D","Q"for indicating the withdrawal,deposit,and quit respectively.The processing will continue until the user enters the code"Q"
程度相当浅
请求给出较明白完整的答案.谢谢了...

// the following is the program in C

#include <stdio.h>
#include <stdlib.h>
void main()
{
float b,b0;
float w,d;
char str[10];
printf("Please enter initial balance: ");
scanf("%f",&b0);
b = b0;
Lab:;
printf("Please enter transaction type: W or D or Q\n");
scanf("%s",&str[0]);
if (strncmp(str,"W",1) == 0 || strncmp(str,"w",1) == 0) {

printf("Please enter the amount of this withdraw\n");
scanf("%f",&w);
b = b - w;
if (b < 0) { printf("this is not allowed--Negative balance\n"); exit(0);}
else { printf("new balance is : %.2f\n",b); goto Lab;};

} else if (strncmp(str,"D",1) == 0 || strncmp(str,"d",1) == 0) {
printf("Please enter the amount of this deposit\n");
scanf("%f",&d);
b =