not sure how to fix this?
I have written this program for an assignment and I have told the program to count the number of deposits and withdrawals then print them when the user is finished. My problem is that it also counts when a deposit = 0 or a withdrawal = 0. I have an idea but I dont know how to write it, maybe something like this?
if (deposit == 0)
then disregard count
Can someone give me some advice please
/* this program prompts the user to enter a starting balance, /
then prompts the user to enter a deposit amount, /
then prompts for a withdrawal amount, /
then gives the user an option to continue or exit the program, /
if input continue loops again, if input exit prints total deposit, withdrawals /
and end balance including %1 applied to all transactions */
#include <stdio.h>
#include <conio.h>
void main(void)
{
float tax, balance[2], deposit, withdraw, total[2] = {0, 0};
char answer;
int count[2] = {0, 0};
clrscr();
printf("This program will calculate the closing account balance based\n");
printf("on your inputs. On exit it will give you a total of the\n");
printf("deposits, withdrawals, tax and closing balance.\n\n");
printf("Please enter your opening account balance:($)");
scanf("%f", &balance[0]);
fflush(stdin);
clrscr();
do
{
printf("Enter a deposit amount:($)");
scanf("%f", &deposit);
fflush(stdin);
total[0] = total[0] + deposit; /* accept deposit and add to deposit total */
count[0] = count[0] + 1; /* count number of deposits */
printf("Enter a withdrawal amount:($)");
scanf("%f", &withdraw);
fflush(stdin);
total[1] = total[1] + withdraw; /* accept withdrawal and add to withdrwal total */
count[1] = count[1] + 1; /* count number of withdrawals */
clrscr();
printf("Your deposit is equal to $%0.2f\n", deposit);
printf("Your withdrawal is equal to $%0.2f\n", withdraw);
printf("\nHave you finished entering deposits or withdrawals?(y/n)\n");
scanf("%c", &answer);
fflush(stdin);
}
while (answer == 'n' || answer == 'N');
if (answer == 'y' || answer == 'Y')
clrscr();
{
printf("\nYour opening balance was $%0.2f\n", balance[0]);
printf("\nThe number of deposits are %d and total amount is $%0.2f\n", count[0], total[0]);
printf("\nThe number of withdrawals are %d and total amount is $%0.2f\n", count[1], total[1]);
tax = (total[0] * 0.01) + (total[1] * 0.01); /* calculate tax */
printf("\nThe total goverment tax at 1 percent per transaction is $%2.2f\n", tax);
balance[1] = balance[0] + total[0] - total[1] - tax; /* calculate closing balance */
printf("\nYour closing balance is $%0.2f\n", balance[1]);
if (balance[1] < 0)
printf("Easy on the withdrawals, your account is not looking so good :-(\n");
else
printf("Keep those deposits coming! :-)\n");
printf("\n\n\nThanks for using my program, See ya later!\n");
printf("Brought to you by ZeD\n");
}
scanf("%c");
fflush(stdin);
}