The program that I want to do is a program that lets you deposit and withdraw money, and that it can display the total amount that you have inputted in the transaction.
Now my problem is, I don't know how to display the total amount and how to do a loop so that I can continuously deposit and withdraw money. Please Help me.

Here is the Code that I have done so far.

#include<stdio.h>
#include<stdlib.h>
 
int main()
{
	int option, a;
	float deposit, withdraw, accountbal[10], totalbalance;
		
	do
	{
		system("cls");
		printf("\n\t=====================================");
		printf("\n\t           M's ATM Machine");
		printf("\n\t=====================================");
		printf("\n\n\tWhat Would You Like To Do?");
		printf("\n\n\tMake a Deposit .......................... [1]");
		printf("\n\n\tMake a Withdrawal ....................... [2]");
		printf("\n\n\tView Account Balance .................... [3]");
		printf("\n\n\tExit the program......................... [0]");
		printf("\n\n\tEnter Option: ");
		scanf("%d",&option);
		switch(option)
				{
				case 1:
					system("cls");
					printf("How much would you like to deposit?\n\n");
					printf("Please Enter the Value Here: ");
					scanf("%f", &deposit);
					if (deposit >= 10000)
					{
						printf("\n\nOnly able Deposit a Maximum of $10000.00.\nPlease Try Again. \n\n");
						printf("Press any key to Continue...");
						fflush(stdin);
						getchar();
						break;
						return 0;
					}
					break;
				case 2:
					system("cls");
					printf("How much would you like to Withdraw?\n\n");
					printf("Please Enter the Value Here: ");
					scanf("%f", &withdraw);
					if (withdraw >= 5000)
					{
						printf("\n\nYou are Only able withdrawal a Maximum of $500.00.\nPlease Try Again. \n\n");
						printf("Press any key to Continue...");
						fflush(stdin);
						getchar();
						break;
						return 0;
					}
					break;
				case 3:
					system("cls");
					printf("Your Account Balance as of today is: \n\n");
					printf("%f", &totalbalance);
					printf("\n\nPress any key to Continue...");
					break;
				case 0:
					printf("\n\n\tThank You for Using Melvin's ATM Machine!... ");
					break;
				default:
					printf("\n\n\tWrong Choice!");
					printf("\n\n\tPress Enter To Start Again ... ");
					fflush(stdin);
					getchar();
					break;
		}

	}while(option!= 0);
			 return 0;

			 for (a=0;;a++);
				{
					accountbal[a] = deposit - withdraw;
					totalbalance = totalbalance + accountbal[a];
				}
	
}

Recommended Answers

All 2 Replies

You can create a seperate ''refresh'' function and run it every time you deposit / withdraw money to calculate the 'balance'.
Then when someone chooses the balance option use printf("You have $%d on your account.",totalbalance);

As for the loop to continuously keep withdrawing or depositing, you can do the same thing you did with your main menu. The same logic applies there as with the main menu.
This is one of the reasons that you might want to seperate the code into seperate functions, so the main function does not get cluttered with while loops and switches.

If you've looked at your code and *still* see no way to mimic your main menu to do the same for the deposit / withdraw menu's just say so and I'll give more detailed help.

Just realized that you used float for totalbalance, in which case it is %f instead of %d :p

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.