| | |
C Programming-Adding overdraft fee
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Apr 2006
Posts: 2
Reputation:
Solved Threads: 0
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
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.
•
•
Join Date: Feb 2006
Posts: 54
Reputation:
Solved Threads: 2
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!!
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;
•
•
Join Date: Apr 2006
Posts: 164
Reputation:
Solved Threads: 10
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:
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.
C Syntax (Toggle Plain Text)
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.
A Perfect World
![]() |
Similar Threads
- Is The Gov't Getting Rid Of Cash And Coins (Geeks' Lounge)
- Java BankAccount program (Java)
- programming in C using Visual C++.net (C++)
Other Threads in the C Forum
- Previous Thread: HTTP request in C
- Next Thread: What am I doing wrong?
| Thread Tools | Search this Thread |
#include adobe ansi api array arrays asterisks binarysearch calculate centimeter changingto char convert copyimagefile cprogramme creafecopyofanytypeoffileinc csyntax database directory dynamic fflush file fork forloop framework frequency getlasterror givemetehcodez grade graphics gtkgcurlcompiling hacking hardware highest histogram inches include incrementoperators input iso kernel km linked linkedlist linux linuxsegmentationfault list lists locate logical_drives looping loopinsideloop. lowest match matrix microsoft motherboard multi mysql number opendocumentformat opensource owf pattern pdf performance pointer posix probleminc process program programming radix recursion recv repetition research reversing scanf scripting segmentationfault sequential shape socket socketprograming stack standard string strings systemcall testing threads turboc unix user variable voidmain() wab windows.h windowsapi





