473,396 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

ATM program in C

Hi, I'm a beginner and I want to know if there's anything wrong with my program so far.

Also, part of our assignment is to show the user how many withdrawals and deposits have been done by the user, but I have no idea how to approach this. Any help would be great

Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2.  
  3. void print_greeting (void);
  4. void print_menu (void);
  5. float get_positive_value(void);
  6. float withdrawal (float balance, float withdrawal_amt);
  7. float deposit (float balance, float deposit_amt);
  8. void print_receipt (int total_withdrawals, int total_deposits, float beg_balance, float balance);
  9.  
  10. int main()
  11. {
  12.   float beg_balance ;
  13.   float balance ;
  14.   int choice;
  15.   float withdrawal_amt;
  16.   float deposit_amt;
  17.  
  18.  
  19.  
  20.   print_greeting();
  21.  
  22.   beg_balance= get_positive_value();
  23.   balance = beg_balance;
  24.   /*Display menu*/
  25.   print_menu();
  26.  
  27. do
  28.   {
  29.     printf("Choose an option\n");
  30.     scanf("%d", &choice);
  31.     if(choice == 1){
  32.       printf("How much do you want to withdraw? ");
  33.       scanf("%f", &withdrawal_amt);
  34.       balance =  withdrawal(withdrawal_amt, balance);
  35.       print_menu();
  36.     }
  37.     else if(choice == 2){
  38.       printf("How much do you want to deposit? ");
  39.       scanf("%f", &deposit_amt);
  40.       balance = deposit(deposit_amt, balance);
  41.       print_menu();
  42.     }
  43.     else if(choice == 3){
  44.       printf("Will fill in later");
  45.       print_menu();
  46.     }
  47.     else if(choice == 4){
  48.   return 0;
  49. }
  50.  
  51. void print_greeting (void)
  52. {
  53.   printf("Welcome to your checking account! This account stores your money.\n\n");
  54.   printf("With this account, you will be able to deposit and withdraw money.\n");
  55.   printf("This will allow you to keep track of your money whenever you want.\n\n\n");
  56. }
  57.  
  58. void print_menu (void)
  59. {
  60.   printf("1)    Make a Withdrwawal\n");
  61.   printf("2)    Make a Deposit\n");
  62.   printf("3)    Display Account Summary\n");
  63.   printf("4)    Quit\n");
  64.  
  65. float get_positive_value (void)
  66. {
  67.   float beg_balance;
  68.  
  69.  printf("Please enter the beginning balance:");
  70.  scanf("%f", &beg_balance);
  71.  
  72.  if(beg_balance < 0){
  73.    printf("Enter a positive integer: ");
  74.    scanf("%f", &beg_balance);
  75.    }
  76.  return beg_balance;
  77. }
  78.  
  79.  
  80. float withdrawal (float balance, float withdrawal_amt)
  81. {
  82.   float beg_balance = 0;
  83.  
  84.   balance = beg_balance - withdrawal_amt;
  85.   return balance;
  86. }
  87.  
  88. float deposit (float balance, float deposit_amt)
  89. {
  90. float beg_balance = 0;
  91.  
  92.   balance = beg_balance + deposit_amt;
  93.   return balance;
  94. }
  95.  
  96.  
  97. void print_receipt (int total_withdrawals, int total_deposits, float beg_balance, float balance)
  98. {
  99.   printf("Beginning balance: %f", beg_balance);
  100.   printf("Ending balance: %f", balance);
  101.  
  102.  
  103. }
  104.  
Apr 17 '14 #1
1 1405
weaknessforcats
9,208 Expert Mod 8TB
Does your program work?

If it does, then there is nothing wrong with it.

As a beginner, to count deposits, use a global variable. Set it to zero in main() and add one to t every time you make a deposit. When your program ends, you will have the number of deposits.
Apr 17 '14 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

22
by: edgrsprj | last post by:
PROPOSED EARTHQUAKE FORECASTING COMPUTER PROGRAM DEVELOPMENT EFFORT Posted July 11, 2005 My main earthquake forecasting Web page is: http://www.freewebz.com/eq-forecasting/Data.html ...
0
by: Tom Lee | last post by:
Hi, I'm new to .NET 2003 compiler. When I tried to compile my program using DEBUG mode, I got the following errors in the C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7 \include\xdebug...
11
by: christopher diggins | last post by:
I am wondering if any can point me to any open-source library with program objects for C++ like there is in Java? I would like to be able to write things like MyProgram1 >> MyProgram2 >>...
1
by: Eric Whittaker | last post by:
hi all, im trying to write my first c++ program. a success, but i can't get the window to stay open after user enters input. it just automatically closes. right now the end of my program looks...
1
by: sylsau | last post by:
Hello, I wrote a JAVA program which uses the JAVA API JDOM 1.0 (of this site www.jdom.org) I put the archive jdom.jar in the directory /usr/share/java/jdom.jar and I added this path in the...
9
by: Hemal | last post by:
Hi All, I need to know the memory required by a c program. Is there any tool/utility which can give me the memory usage in terms of DATA segment, TEXT segment, BSS segment etc. I am working...
7
by: ibtc209 | last post by:
I just started programming in C, and I need some help with this problem. Your program will read the information about one MiniPoker hand, namely the rank and suit of the hand’s first card, and...
109
by: zaidalin79 | last post by:
I have a java class that goes for another week or so, and I am going to fail if I can't figure out this simple program. I can't get anything to compile to at least get a few points... Here are the...
0
amitpatel66
by: amitpatel66 | last post by:
There is always a requirement that in Oracle Applications, the Concurrent Program need to be execute programatically based on certain conditions/validations: Concurrent programs can be executed...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.