I am having problems completing this program. I have included my notes, and stated current problems in the beginning.
Please help. I have no idea what I am doing. This is all I have accomplished in 4 days! I am new to programming, well relatively, it was nearly 17 years ago last time I wrote any code.

/*Current Problems which need to be fixed:
After aasking for the account number it requires you to enter the account number 2 times.
Then prints the menu 2 times.
Then does not give the option of choosing menu options.*/

/* Basic Accounting Program for beginners: 
Input debits (DB) and credits (CR) and allow for 1,000,000 DB and CR transactions. 
Start accounts with a zero balance.
Do not allow account balance to go below 0.
At the end of 31 days, print out account number and balances for 25 different accounts.*/

#include <stdio.h>
#define DAY 31


int main(void)
{
	printf("Basic Accounting Program\n");
	
	int acct = 0;
	int count, factorial;
	int choice = 0;

	for (count = 1; count < DAY ; count++)
		
	{
		printf ("Day %d\n",count);
		printf ("Input account numbers only, if anything else the program will exit, thank you!\n");
		scanf ("%d\n", &acct);

		/*?why will it not proceed to next step without entering the account number 2 times?*/

			printf ("\Please choose an option below\n");
			printf ("\t1. Credit\n");
			printf ("\t2. Debit\n");
			printf ("Please enter your choice: \n");

		/*?Prints menu (at this point 2 times) then the program stops, why will it not go to my if else statements?*/

		if (choice = 1)
			printf ("Input CR\n");
		else if (choice = 2)
			printf ("Input DB\n");
		else if (choice != 1, 2)
			printf ("\Please choose an option below\n");
			printf ("\t1. Credit\n");
			printf ("\t2. Debit\n");
			printf ("Please enter your choice: \n");
			break;

	}
	
	/*do sum of 31 days here*/

	return 0;
}

Edited 7 Years Ago by MeBjess: Include more info

Comments
good first post.

Well this looks like a c program (not a c++) so I will assume that you are in C and carry on.

The first question is that you have unfortunely added a \n after the %d in the scanf statement. That means if first looks for a number and then and extra return. So remove the \n and things will be ok.

Next problem is that you don't ask for a choice. You print the question but have forgotten to actually get user input (e.g. with a scanf)
then choice is zero and things go wrong.

Ntex you have written else if (choice != 1,2) this is not the correct way to write this you since it . This statement means find the result of choice != 1 then find the result of 2 and if that answer is true execute the statement below Well 2 is always true so it works. Much simpler was to write else .
[NOTE::
you could write else if (choice!=1 || choice!=2) .

finally : You don't want the break at the end.

Best of luck with it. What did you program 17 years ago, basic or assembler I guess. If it is the latter you will pick this up really quickly.
(Maybe fortran? -- again this wont be problem after pointers).

If you want lines 45-48 to run only in association with the last else if, then they should be enclosed in a code block using curly brackets. Probably a better thing, however, would be to output statement to user that the selection entered is invalid and they should try again. Lines 27 through 49 could then be run inside an inner loop as many times as needed until valid input is entered. Valid input could include a third choice, number 3, that will voluntarily exit the program the input loop.

StuXYZ,

It was C code, not C++, my fault.

Also after I fixed the errors I ended up not knowing how to take the difference between the debits and credits. This is for a class, but it seems he has to keep everyone quiet so he can lecture, thus not getting much lecture done. So, I am learning everything on my own. As for now I am going to make notes on the program I have and turn in what I have. But I would like to continue to work on it and get the program to completely do what is required.

Thanks for the help! It helped me tremendously! I get so lost trying to figure out my own errors.

Oh, and what programming I did so many years ago was lost since it was only for a one year class and I have not taken a programming class since. :D

This article has been dead for over six months. Start a new discussion instead.