This is a simple program.. Help me please I think it has an error..

This is a discussion on This is a simple program.. Help me please I think it has an error.. within the C Programming forums, part of the General Programming Boards category; Write a program that will be used to handle Automated Teller Machine Transactions. Such transaction includes; (1) balance inquiry, (2) ...

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    23

    This is a simple program.. Help me please I think it has an error..

    Write a program that will be used to handle Automated Teller Machine Transactions. Such transaction includes; (1) balance inquiry, (2) deposit, (3) withdrawal and say (4) exit. Aside from these, the user should be presented a menu showing these transactions as possible options. (20pts)

    Additional Requirements:
    1. Initial balance is 10,000.00.
    2. Deposit amount should be greater than zero, if the user enters zero or negative amount, the program should print “Deposit amount should be greater than zero”.
    3. Withdrawal amount should not exceed the available balance, if the user enters amount greater than the available balance, the program should print “Withdrawal amount exceeds the available balance.
    4. Withdrawal amount should be greater than zero, if the user enters zero or negative amount, the program should print “Withdrawal amount should be greater than zero.”
    5. Maximum withdrawal amount is 4000.00 per transaction, if the user enters more than 4000.00, the program should print “Maximum withdrawal amount is 4000.00.”
    6. The program should print the current balance for every transaction.
    7. The program should end if and only if the user chooses to exit.

    Heres my program..
    Code:
    #include <stdio.h>
    #include <conio.h>
    double amount=10000.00;
    double dep(double y){
    double newaccount;
    newaccount=amount+y;
    return newaccount;}
    double with(double x){
    double newaccount;
    if(x>=4001)
    printf("The largest amount you can withdraw is 4000");
    else if(x>=10001)
    printf("You exceed to your bank savings");
    else
    newaccount=amount-x;
    printf("%lf",newaccount);
    return 0;}
    
    
    void main()
    {
    int i=0;
    double j;
    clrscr();
    printf("\n*******MENU*********\n");
    printf("1.Balance Enquiry\n");
    printf("2.Deposit\n");
    printf("3.Withdraw\n");
    printf("4.Exit\n");
    printf("Select an item from the menu: ");
    scanf("%d",&i);
    while(i<4)
    {
    switch(i)
    {
    case 1:printf("This is your balance amount: %f",amount);
    break;
    case 2:printf("How much would you like to withdraw?");
    scanf("%lf",&j);
    
    amount = with(j);
    j=0;
    printf("This is your balance amount: %f",amount);
    break;
    case 3:printf("How much amount do want to withdraw?\n");
    scanf("%lf",&j);
    amount = amount-j;
    j=0;
    printf("This is your balance amount: %f",amount);
    break;
    }
    printf("\n*********MENU*********...\n");
    printf("1.Balance Enquiry\n");
    printf("2.Deposit\n");
    printf("3.Withdraw\n");
    printf("4.Exit\n");
    printf("If you are a first time user please deposit some amount for balance enquiry.\n");
    printf("Select an item from the menu: ");
    scanf("%d",&i);
    }
    getch();
    }
    I think i did not accomplish the requirements..

    1. Deposit amount should be greater than zero, if the user enters zero or negative amount, the program should print “Deposit amount should be greater than zero”.
    2. Withdrawal amount should not exceed the available balance, if the user enters amount greater than the available balance, the program should print “Withdrawal amount exceeds the available balance.
    3. Withdrawal amount should be greater than zero, if the user enters zero or negative amount, the program should print “Withdrawal amount should be greater than zero.”
    4. Maximum withdrawal amount is 4000.00 per transaction, if the user enters more than 4000.00, the program should print “Maximum withdrawal amount is 4000.00.”
    5. The program should print the current balance for every transaction.

    So please I hope someone help me to this... I'm so confuse.. and its really confusing...
    Thanks for the help...

  2. #2
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,604
    This code is entirely unreadable. Please indent the code and repost it. If you need help, you can look here.
    Another note is that you should not use void main. Use int main instead.
    You can also replace getch with getchar.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    And if you'll just tell us what the program is doing wrong, we'll look into it, as soon as you indent your code so it's readable.


  4. #4
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    use int main()

    Why when selected the deposit you are asking how much to withdraw?
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  5. #5
    Super unModrator
    Join Date
    Dec 2007
    Posts
    321
    You can make a single menu() function instead of repeating the same thing twice.
    You defined the function dep() but never really used it ??

    Code:
    case 2:printf("How much would you like to withdraw?");
    scanf("&#37;lf",&j);
    
    amount = with(j);
    j=0;
    printf("This is your balance amount: %f",amount);
    option 2 is for deposit and you are asking how much to withdraw!

    and as others said--indent, use int main(), return 0, getchar() instead of getch() and get rid of <conio.h>

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. how do you resolve this error?
    By -EquinoX- in forum C Programming
    Replies: 32
    Last Post: 11-05-2008, 03:35 PM
  3. Quantum Random Bit Generator
    By shawnt in forum C++ Programming
    Replies: 62
    Last Post: 06-18-2008, 10:17 AM
  4. using c++ in c code
    By hannibar in forum C Programming
    Replies: 17
    Last Post: 10-28-2005, 09:09 PM
  5. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21