Like Tree2Likes

Code Assistance

This is a discussion on Code Assistance within the C Programming forums, part of the General Programming Boards category; I entered the equations in to the deposit and withdrawal. It worked, but I didn't add correctly. I got this ...

  1. #16
    Registered User
    Join Date
    Mar 2013
    Location
    West Palm Beach, Florida, United States
    Posts
    13
    I entered the equations in to the deposit and withdrawal.

    It worked, but I didn't add correctly.

    I got this really long negative number when I ran the program.

    But it still updated which means I did something right.

    Code:
    #include <stdio.h>
    #include <math.h>
    #include <ctype.h>
    
    
    #define _CRT_SECURE_NO_WARNINGS
    
    
    
    
    // Displays the list of options available
    //prompts for the user’s selection and sets the value of the selection
    void mainMenu(int *option);
    
    
    //Asks the user if they want another transaction
    void Keepgoing(char *goagain);
    
    
    //Asks the user which type of account they _CRT_SECURE_NO_WARNINGS would like to access and sets the 
    //value of the selection
    void AccountMenu( char *acctType);
    
    
    //Prompts the user for the amount of deposit and updates the selected account 
    void MakeDeposit( double *balance);
    
    
    //Prompts the user for the amount of the withdrawal, determines if there are 
    //sufficient funds and updates the selected account if funds are dispensed 
    void MakeWithdrawal( double *balance, char acctType);
    
    
    //Displays the user’s current account balance for the selected account
    void GetBalance( double balance);
    
    
    int main()
    {
    	int choice,
    		acctType;
    
    
    	char again,
    		account;
    
    
    	double deposit,
    		withdrawal,
    		balance,
    		C=850.00,
    		S=2500.00,
    		E=-1850.00;
    
    
    do{
    	mainMenu(&choice);
    
    
    	printf("\nChoice entered was %d.\n", choice);
    
    
    	AccountMenu(&account);
    
    
    	printf("\nAccount type selected was %c.\n", account);
    		
    	if (choice == 1)
    	{
    		if (account == 'c' || account == 'C')
    			GetBalance(C);
    		if (account == 's' || account == 'S')
    			GetBalance(S);
    		if (account == 'e' || account == 'E')
    			GetBalance(E);
    	}
    
    
    	if (choice == 2)
    	{
    		if (account == 'c'||account == 'C')
    		{
    			MakeWithdrawal(&balance, acctType);
    			C = C - withdrawal;
    		}
    		
    		if (account == 's'||account == 'S')
    		{
    			MakeWithdrawal(&balance, acctType);
    			S = S - withdrawal;
    		}
    
    
    		if (account == 'e'||account == 'E')
    		{
    			MakeWithdrawal(&balance, acctType);
    			E = E - withdrawal;
    		}
    		
    	}
    
    
    	if (choice == 3)
    	{
    		if (account == 'c'||account == 'C')
    		{
    			MakeDeposit(&deposit);
    		C = C + deposit;
    		}
    		
    		if (account == 's'||account == 'S')
    		{
    			MakeDeposit(&deposit);
    		S = S + deposit;
    		}
    		
    		if (account == 'e'||account == 'E')
    		{
    			MakeDeposit(&deposit);
    		E = E + deposit;
    		}
    	}
    
    
    	Keepgoing(&again);
    
    
    } while (again == 'y' || again == 'Y');
    
    
    if(again == 'n')
    {
    	printf("\nThank you. Have a nice day.\n\n",again);
    }
    
    
    	return 0;
    }
    
    
    
    
    void mainMenu(int *option)
    {
    	printf("Welcome to Regional South Bank.\n\n");
    	printf("Please choose from the following.\n\n");
    	printf("1. Check Balance\n");
        printf("2. Withdraw Cash\n");
        printf("3. Deposit Cash\n");
        printf("\nEnter your choice:");
        scanf_s("%d",option);
    }
    
    
    
    
    void Keepgoing(char *goagain)
    {
    	printf("\nWould you like to do another transcation?\n");
    	printf("\nChoose y/n:");
    	scanf_s(" %c",goagain);
    }
    
    
    
    
    void AccountMenu(char *acctType)
    {
    	printf("\nWhich account would like to access?\n");
    	printf("\nC for Checking\n");
    	printf("\nS for Savings\n");
    	printf("\nE for Credit\n");
    	printf("\nChoose an account:");
    	scanf_s(" %c", acctType);
    }
    
    
    
    
    void MakeDeposit(double *balance)
    {
    	printf("\nHow much would you like add:");
    	scanf_s(" %f", balance);
    }
    
    
    
    
    void MakeWithdrawal( double *balance, char acctType)
    {
    	printf("\nHow much would you like to withdraw:");
    	scanf_s(" %lf", balance);
    }
    
    
    
    
    void GetBalance(double balance)
    {
    	printf("\nThe balance is %.2lf.", balance);
    }

  2. #17
    Registered User
    Join Date
    May 2012
    Posts
    1,066
    Code:
    double deposit,
            withdrawal,
    ...
        if (choice == 2)
        {
            if (account == 'c'||account == 'C')
            {
                MakeWithdrawal(&balance, acctType);
                C = C - withdrawal;
            }
            
            if (account == 's'||account == 'S')
            {
                MakeWithdrawal(&balance, acctType);
                S = S - withdrawal;
            }
    
    
            if (account == 'e'||account == 'E')
            {
                MakeWithdrawal(&balance, acctType);
                E = E - withdrawal;
            }
    "withdrawal" is uninitialized and since you don't pass it to MakeWithdrawal() it's value is garbage.

    Bye, Andreas

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Beginner code assistance
    By akust0m in forum C Programming
    Replies: 6
    Last Post: 08-07-2012, 09:29 PM
  2. C code, MD5 hash, if statements assistance
    By letmein in forum C Programming
    Replies: 5
    Last Post: 09-14-2010, 09:25 AM
  3. Hello,i need assistance in completing the code
    By toader in forum C++ Programming
    Replies: 1
    Last Post: 06-22-2009, 03:32 AM
  4. Code Assistance
    By Nezmin2 in forum C Programming
    Replies: 12
    Last Post: 12-18-2008, 11:26 PM
  5. C code assistance please
    By lotus in forum C Programming
    Replies: 7
    Last Post: 05-25-2002, 02:29 AM

Tags for this Thread


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