7 Replies - 7520 Views - Last Post: 17 March 2013 - 07:25 PM Rate Topic: -----

#1 93Dev  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 16-March 13

ATM / Banking Program Inquiry

Posted 16 March 2013 - 02:14 PM

The assignment is attatched if you need a better idea of what I'm trying to do.
This is what I have.
I've commented out what I have not worked on yet as I try to get it done piece by piece.

Question) Should the Switch Case statement be inside main( ) or in the function definition. If its supposed to be in main, how do I get the ptr *option to be recognized/read outside of the function definition.

Assistance) I believe a do/while loop is what I should use to get the program to loop when the user enters Y for the Keepgoing function but how that loop should is to look/be written I don't know.

Assistance) When the user enters their Y or N response, I want to make sure its in upper case.

scanf(" %c",goAgain);
*goAgain = toupper(*goAgain);

Don't understand pointers well, and how to get toupper or the compiler to not give me fits about the variable type

Any further help or heads up as I continue through this project would be welcomed and much appreciated.

 
#define _CRT_SECURE_NO_DEPRECATE
#include<stdio.h>
#include<ctype.h>
#include<math.h>

/* 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 
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( )
{
	char	again;		// Yes or No Loop option
	int	transtype;	// (1) for DEPOSIT, (2) for WITHDRAWAL, (3) for ACCOUNT BALANCE, (4) for TRANSFER
	char	transacc;	// (C) for CHECKING, (S) for SAVINGS, (R) for CREDIT
	double	check = 850.00;	// Cash amounts in each account
	double	savings = 2500.00;
	double	credit = -1850.00;	
	
	MainMenu(&transtype);

	Keepgoing(&again);
}

void MainMenu(int *option)
{
	printf("Welcome to FAU's #1 Bank.\nPlease choose an action from the following:\n\n");
	printf("1. Check Account Balance\n");
    printf("2. Withdraw\n");
    printf("3. Deposit\n");
    printf("4. Transfer\n");
    printf("\nEnter the number corresponding to your choice: ");
    scanf("%d",option);
	
	switch (*option) {
	case 1:
			printf("\n\nYou selected 'Check Account Balance'\n");
			break;
	case 2:
			printf("\n\nYou selected 'Withdraw'\n");
			break;
	case 3:
			printf("\n\nYou selected 'Deposit'\n");
			break;
	case 4:
			printf("\n\nYou selected 'Transfer'\nTo transfer money, first withdraw from the specified account.");
			printf("\nThen deposit that money into the receiving account.\n");
			break;
		}
}

void Keepgoing(char *goAgain)
{
	printf("\n\nDo you wish to make another transcation?\n");
    printf("Enter Y (Yes) / or N (No) ");
    scanf(" %c",goAgain);
}

/*
void AccountMenu(char *acctType)
{
	printf("\nPlease choose an account from following:\n");
    printf("\n(C) - Checking");
    printf("\n(S) - Savings");
    printf("\n(R) - Credit\n");
    printf("\nEnter the letter corresponding to your choice: ");
    scanf(" %c",acctType);
}

void MakeDeposit(double *balance)
{

}

void MakeWithdrawal(double *balance, char acctType)
{

}

void GetBalance(double balance)
{

}
*/

Attached File(s)



Is This A Good Question/Topic? 0
  • +

Replies To: ATM / Banking Program Inquiry

#2 jimblumberg  Icon User is online

  • member icon


Reputation: 4278
  • View blog
  • Posts: 13,432
  • Joined: 25-December 09

Re: ATM / Banking Program Inquiry

Posted 16 March 2013 - 02:36 PM

Quote

I've commented out what I have not worked on yet as I try to get it done piece by piece.

You could leave the blank function implementations in place without the comment, the program should still compile. Just make sure to return something from the non-void functions. But there is noting wrong with the comment.

Quote

Question) Should the Switch Case statement be inside main( ) or in the function definition. If its supposed to be in main, how do I get the ptr *option to be recognized/read outside of the function definition.


This is really a design issue. But by the looks of the prototypes the loop should be in main, as well as the switch statement. This is because you aren't passing the variables into the menu function that are needed to call the other functions.

Quote

Assistance) I believe a do/while loop is what I should use to get the program to loop when the user enters Y for the Keepgoing function but how that loop should is to look/be written I don't know.


A simple do/while(again == 'Y') type loop should work.

Quote

Assistance) When the user enters their Y or N response, I want to make sure its in upper case.

scanf(" %c",goAgain);
*goAgain = toupper(*goAgain);


That is the purpose of toupper() to make the character upper case. The way you're using toupper() looks correct if that is inside the Keepgoing() function.

Jim
Was This Post Helpful? 1
  • +
  • -

#3 93Dev  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 16-March 13

Re: ATM / Banking Program Inquiry

Posted 16 March 2013 - 03:23 PM

Thank you for your reply and help.
I've added in your advice, the only problem that remains is moving the switch cases into the main( ).
#define _CRT_SECURE_NO_DEPRECATE
#include<stdio.h>
#include<ctype.h>
#include<math.h>

/* 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 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( )
{
	char	again = 'Y';			// Yes or No Loop option
	int		transtype, *option;				// (1) for DEPOSIT, (2) for WITHDRAWAL, (3) for ACCOUNT BALANCE, (4) for TRANSFER
	char	transacc;				// (C) for CHECKING, (S) for SAVINGS, (R) for CREDIT
	double	check = 850.00;			// Cash amounts in each account
	double	savings = 2500.00;
	double	credit = -1850.00;	
	
	do
	{
	MainMenu	(&transtype);
			switch (*option)
		{
			case 1:
				printf("\n\nYou selected 'Check Account Balance'\n");
				break;
			case 2:
				printf("\n\nYou selected 'Withdraw'\n");
				break;
			case 3:
				printf("\n\nYou selected 'Deposit'\n");
				break;
			case 4:
				printf("\n\nYou selected 'Transfer'\nTo transfer money, first withdraw from the specified account.");
				printf("\nThen deposit that money into the receiving account.\n");
				break;
		}
	}while(again == 'Y');
	Keepgoing	(&again);
}

void MainMenu(int *option)
{
	printf("Welcome to FAU's #1 Bank.\nPlease choose an action from the following:\n\n");
	printf("1. Check Account Balance\n");
    printf("2. Withdraw\n");
    printf("3. Deposit\n");
    printf("4. Transfer\n");
    printf("\nEnter the number corresponding to your choice: ");
    scanf("%d",option);
}

void Keepgoing(char *goAgain)
{
	printf("\n\nDo you wish to make another transcation?\n");
    printf("Enter Y (Yes) / or N (No) ");
    scanf(" %c",goAgain);
	*goAgain = toupper(*goAgain);
}



I don't understand pointers to well, but since the functions are void, I believe they are what I need to take the value of option back to main for the switch case statement. What variable to put/how to get the value to go back to the main for the switch statement eludes my crude attempts.
Was This Post Helpful? 0
  • +
  • -

#4 jimblumberg  Icon User is online

  • member icon


Reputation: 4278
  • View blog
  • Posts: 13,432
  • Joined: 25-December 09

Re: ATM / Banking Program Inquiry

Posted 16 March 2013 - 03:35 PM

I don't understand pointers to well, but since the functions are void, I believe they are what I need to take the value of option back to main for the switch case statement.

Correct.

Quote

What variable to put/how to get the value to go back to the main for the switch statement eludes my crude attempts.

Since this is where the variable was defined you are not dealing with a pointer you are dealing with the variable. So you don't need the pointer reference.

	do
	{
	MainMenu	(&transtype);
			switch (option)  // You don't need the *.


Also since you sent transtype to the function you should probably use that variable in your switch.

In the following snippet:
	}while(again == 'Y');
	Keepgoing(&again);


The function needs to be inside the while statement. That function is altering again.

You should probably also have a default case for your case statement to insure that the user only enters a correct value.

Jim

This post has been edited by jimblumberg: 16 March 2013 - 03:37 PM

Was This Post Helpful? 0
  • +
  • -

#5 93Dev  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 16-March 13

Re: ATM / Banking Program Inquiry

Posted 16 March 2013 - 11:49 PM

In my main function, I have several variables.
double	check	= 850.00;
double	savings = 2500.00;
double	credit	= -1850.00;



I want to use those variables in a user-defined function. You don't re-initialize them inside of it.
void MakeWithdrawal(double *balance, char acctType)
{
	double	ch1 = 0;
	double	sv1 = 0;
	double	cd1 = 0;
	
	if(acctType == 'C')
	{
		printf("\nHow much would you like to withdraw from your Checking account? ");
		scanf("%d",&ch1);

//check = check - ch1; ??

	}
	if(acctType == 'S')
	{
		printf("How much would you like to withdraw from your Savings account? ");
		scanf("%d",&ch1);
	}
	if(acctType == 'R')
	{
		printf("How much would you like to withdraw from your Credit account? ");
		scanf("%d",&ch1);
	}
}




The only 2 things I can think of is:

1)create new variables inside the function equal to the needed value then set the variable equal to the new answer (newValue = newValue - withdraw) but i'm not sure if that is viable/fool-proof with the loop and if the tester does multiple transactions.

2)doing something with some pointers again...

Either way I'm not sure and was in need of some assistance
Was This Post Helpful? 0
  • +
  • -

#6 jimblumberg  Icon User is online

  • member icon


Reputation: 4278
  • View blog
  • Posts: 13,432
  • Joined: 25-December 09

Re: ATM / Banking Program Inquiry

Posted 17 March 2013 - 05:20 AM

Quote

I want to use those variables in a user-defined function. You don't re-initialize them inside of it.

Yes, you pass the required variables into the function using your parameters. Since you are passing the balance by pointer any change made in the function is reflected in the calling function. In your snippet above you would add the change to the balance. But that snippet should be generating warnings, you are using the incorrect specifier for the type of variable, "%d" is for an int not a double. You use "%f" for float and "%lf" for a double. Here is your function reworked to reflect the changes.
void MakeWithdrawal(double *balance, char acctType)
{
	double	ch1 = 0;

	if(acctType == 'C')
	{
		printf("\nHow much would you like to withdraw from your Checking account? ");
	} else if(acctType == 'S')
	{
		printf("How much would you like to withdraw from your Savings account? ");
	} else if(acctType == 'R')
	{
		printf("How much would you like to withdraw from your Credit account? ");
	}
   else
   { // Add a little error checking of the account type.
      printf("You entered an incorrect account please try again.\n");
      return;
   }
   scanf("%lf",&ch1);  // Be sure to always use the correct specifier for the type.

   *balance -= ch1;
}




Jim
Was This Post Helpful? 1
  • +
  • -

#7 93Dev  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 16-March 13

Re: ATM / Banking Program Inquiry

Posted 17 March 2013 - 12:31 PM

Thank you again. Your help is much appreciated. Got all previous issues worked out.
Compiled, tested, revised, then moved onto the next user-defined function & function definition.
Currently on the last one with every previous one running smoothly.

void GetBalance(double balance)
{

}



This one has stumped me. It was thinking just making balance = check in the case statement would be all I needed, but i need to use the user defined function (assignment requirement).
I don't know what to put inside the function to get the desired account balance printed.

The biggest problem is calling it.

GetBalance(balance); // Its in the Case 1 statement, which is the option for Checking balance

void GetBalance(double balance)
{
     printf("Hi"); // Just to see it run after being called
}



I get an error as the program runs "The variable 'balance' is being used without being initialized.
I though a & in the call would solve that but no.

I though since I've used balance so much lets use a different variable
Short hand of the variables that i changed to amount for this one function.
void GetBalance(double amount);

int main( )
{	
double amount;
GetBalance(amount);
}

void GetBalance(double amount)
{
printf("Hi");
}



Same problem, when executing the program, where the function is called it crashes.

Suggestions?
Was This Post Helpful? 0
  • +
  • -

#8 93Dev  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 16-March 13

Re: ATM / Banking Program Inquiry

Posted 17 March 2013 - 07:25 PM

I got it.

GetBalance(check); GetBalance(savings); GetBalance(credit); //each inside designated case statement
 
void GetBalance(double balance)
{
    printf("Current funds; $%.2lf\n",balance);
}


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1