C Programming-Adding overdraft fee

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Apr 2006
Posts: 2
Reputation: Mr T. is an unknown quantity at this point 
Solved Threads: 0
Mr T. Mr T. is offline Offline
Newbie Poster

C Programming-Adding overdraft fee

 
0
  #1
Apr 9th, 2006
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
Last edited by alc6379; Apr 11th, 2006 at 1:29 pm. Reason: added Code tags.
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 2
Reputation: Mr T. is an unknown quantity at this point 
Solved Threads: 0
Mr T. Mr T. is offline Offline
Newbie Poster

Re: C Programming-Adding overdraft fee

 
0
  #2
Apr 9th, 2006
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.
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 54
Reputation: HackWizz is an unknown quantity at this point 
Solved Threads: 2
HackWizz HackWizz is offline Offline
Junior Poster in Training

Re: C Programming-Adding overdraft fee

 
0
  #3
Apr 10th, 2006
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!!
return 0;
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 54
Reputation: HackWizz is an unknown quantity at this point 
Solved Threads: 2
HackWizz HackWizz is offline Offline
Junior Poster in Training

Re: C Programming-Adding overdraft fee

 
0
  #4
Apr 10th, 2006
And use tags


  1. like this
return 0;
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 164
Reputation: orko is an unknown quantity at this point 
Solved Threads: 10
orko orko is offline Offline
Junior Poster

Re: C Programming-Adding overdraft fee

 
0
  #5
Apr 10th, 2006
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:
  1. if(fwithamount>bal) {
  2. printf("\nYour new balance is $%.2f\n",bal-fwithamount-35);
  3. bal=bal-fwithamount-35;
  4. } else {
  5. printf("\nYour new balance is $%.2f\n",bal-fwithamount);
  6. bal=bal-fwithamount;
  7. }

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.
A Perfect World
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC