I have been working on this code for a banking program I am trying put together. Trying to test my ability to grasp this stuff on my own. I am stuck on this part and maybe it is my non-math mind that is causing a block. Can someone help me understand where I put the if statement to denote that if the account is overdrawn it is charged an overdraft fee of $35. Even if you don't write it out in code and explaination would be phenomenal. I'm really lost on some of these rules.

Here is the code I have so far

#include <stdio.h>


Main ( )
{


int iSelection,iresponse,n,y;
float fwithamount,bal,fdepamount;


printf("Please enter amount of initial deposit.\n");
scanf("%f",&fdepamount);
bal=fdepamount;
while(iresponse != 1)
{
printf("\nWould you like to make another transaction?\n");
printf("\n1\tno\n");
printf("2\tyes\n");
printf("\nEnter your selection:\n ");
scanf("%d",&iresponse);


/* This Branch describes the program actions when the customer selects whether or not to perform an additional transaction. */
if(iresponse == 1)
{
printf("Your balance is $%.2f",bal);
break;
} //end if
if(iresponse == 2) {
printf("\n1\tDeposit Funds\n");
printf("2\tWithdraw Funds\n");
printf("\nEnter your selection: ");
scanf("%d",&iSelection);
} //end if
if (iSelection == 1) {
printf("\nEnter fund amount to deposit: ");
scanf("%f",&fdepamount);
printf("\nYour new balance is: $%.2f\n",bal+fdepamount);
bal=bal+fdepamount;
} //end if
if (iSelection == 2) {
printf("\nEnter fund amount to withdraw: ");
scanf("%f",&fwithamount);
printf("\nYour new balance is $%.2f\n",bal-fwithamount);
bal=bal-fwithamount;
} //end if
} //end while loop
getchar();
} //end main function

Now that I am looking at this thing I must have inserted the loop incorrectly too. If anyone has any idea what I did wrong there too I'm open. Though it was working, but its calculating the balance wrong.

Write The code according to your thinking..when and how do you calculate manually..simple when the user enters see
if there is a overdrawing
..if yes then deduct 35 and display the balance(i.e. after -35 and not
-fwithamount)..dont allow -fwithamount..
if no then
allow the normal procedure

hope you get it!!

And use

tags

like this

u can use debugging tool or watch function of ur compiler for better understanding wat u made wrong..... n the thing is i have run ur program.... it seems like it z working fine.... okay for overdraw:

if(fwithamount>bal) {
          printf("\nYour new balance is $%.2f\n",bal-fwithamount-35); 
          bal=bal-fwithamount-35;
} else {
          printf("\nYour new balance is $%.2f\n",bal-fwithamount); 
          bal=bal-fwithamount; 
}

some more problems with ur program.
1. check if thr is any negative value entered. (use a user-defined check_negative() function)
2. check if thr is any other invalid entry is given.
3. look for other misuse can be done n solve those issues..... otherwise, i ll have to grab some extra cash using this software.... lol... j/k..... cheers.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.