This is part of some class work I have to do, but this is not what I am turning in as my assignment! It does have some bugs, but as long as the user only enters an integer it runs fine.

I have included just the part of the code that I need help with. It compiles and runs through the program, but does do what I want it do.

I have 2 questions, one is how do I get the CR entered to save to the account? And the second is, once it is stored, how do I display that information? More details are in block comments in the code. I hope my question is clear.

/*Current Problems which need to be fixed:
Input account number and be able to change the account balance accordingly.
When prompted, display the account balance accordingly.
*/

#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define DAY 2
#define MAXACCT 25



int main(void)
{
	printf("Basic Accounting Program\n\n");
	
	int acct;
	int count, factorial;
	int choice = 0;
	long credit;
	int debit = 0;
	int j = 0;
	int bal;
/*these are declared from another program, using them as aides in understanding*/
	long balance[MAXACCT];
	long jacct[MAXACCT];
	int thisacct;
	int thisamt;
	int i;
	int foundacnt;
	char input[25];
	char rtrn;
/*end of items declared from other program*/



	for (count = 1; count < DAY ; count++)
	{
		printf ("Day %d\n\n",count);

here1:
			printf ("Input account number, thank you!\n");
			rtrn = scanf ("%d", &jacct);
here:
			printf ("\nPlease choose an option below\n");
			printf ("\t1. Credit (Charge Card Transaction: CR)\n");
			printf ("\t5. Account Balance\n");
			printf ("\t8. Exit\n");
			printf ("Please enter your choice: \n");
			scanf ("%d", &choice);
		
			if (choice == 1)
			{
				printf ("Input CR\n");
				scanf ("%d", &credit); 
				/*how do i get the credit (money added) to 
                                be  applied to the account?
				for example, suppose I choose option 1 
                                two times, how do I make the first CR add 
                                to the 2nd CR?*/
				bal = 0 + credit;
				goto here;
			}
			else if (choice == 5)
			{
				printf ("Your account balance is %d\n", bal); 
				/*how do i save and output the 
                                adjusted balance?
				for example, suppose I entered two CR 
                                (option 1) transactions, the first time I CR 
                                the account 5, then 10,
				so now I want the balance to say 15.*/
				goto here;
			}
			else if (choice == 8)
			{
				return (0);
			}
			else if (choice != 1 || choice != 5 || choice != 8)
			{
				printf ("OOPS!  Invalid Entry!\n");
				goto here;
			}
here2:	;	
	}
return 1;
}

Recommended Answers

All 2 Replies

To save the transaction you are almost there. int bal = 0; /* initialize balance to zero */ instead of bal = 0 + credit; replace for bal = bal + credit; or bal += credit; which is a shortcut.

Thank you! It is so easy to over look the simple things sometimes.

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.