| | |
Beginers Basic Account Program
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2009
Posts: 7
Reputation:
Solved Threads: 0
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.
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.
C++ Syntax (Toggle Plain Text)
/*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; }
Last edited by MeBjess; Oct 12th, 2009 at 4:27 pm. Reason: Include more info
•
•
Join Date: Nov 2008
Posts: 392
Reputation:
Solved Threads: 72
0
#2 Oct 12th, 2009
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
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
[NOTE::
you could write
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).
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).
experience is the most expensive way to learn anything
•
•
Join Date: Jul 2005
Posts: 1,673
Reputation:
Solved Threads: 261
0
#3 Oct 12th, 2009
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.
Klatu Barada Nikto
•
•
Join Date: Oct 2009
Posts: 7
Reputation:
Solved Threads: 0
0
#4 Oct 12th, 2009
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.
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.
![]() |
Similar Threads
- Question answer database program in Visual Basic 6 (Visual Basic 4 / 5 / 6)
- Help! on Basic Mash Python Program (Python)
- Basic Cryptography Program Help (Python)
- What's the HARDEST program you've written? (Computer Science)
- BASIC Editor: Where Did I Go Wrong? (C)
- Very basic de/encrypt program (Python)
- how can i make VB detect key presses on another program (Visual Basic 4 / 5 / 6)
- Wierd error messages with calculator program (C++)
Other Threads in the C++ Forum
- Previous Thread: Recusion Problem-Help
- Next Thread: hamming code in C++
| Thread Tools | Search this Thread |
api array based binary bitmap c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news node number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






