Beginers Basic Account Program

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2009
Posts: 7
Reputation: MeBjess is an unknown quantity at this point 
Solved Threads: 0
MeBjess MeBjess is offline Offline
Newbie Poster

Beginers Basic Account Program

 
1
  #1
Oct 12th, 2009
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.

  1. /*Current Problems which need to be fixed:
  2. After aasking for the account number it requires you to enter the account number 2 times.
  3. Then prints the menu 2 times.
  4. Then does not give the option of choosing menu options.*/
  5.  
  6. /* Basic Accounting Program for beginners:
  7. Input debits (DB) and credits (CR) and allow for 1,000,000 DB and CR transactions.
  8. Start accounts with a zero balance.
  9. Do not allow account balance to go below 0.
  10. At the end of 31 days, print out account number and balances for 25 different accounts.*/
  11.  
  12. #include <stdio.h>
  13. #define DAY 31
  14.  
  15.  
  16. int main(void)
  17. {
  18. printf("Basic Accounting Program\n");
  19.  
  20. int acct = 0;
  21. int count, factorial;
  22. int choice = 0;
  23.  
  24. for (count = 1; count < DAY ; count++)
  25.  
  26. {
  27. printf ("Day %d\n",count);
  28. printf ("Input account numbers only, if anything else the program will exit, thank you!\n");
  29. scanf ("%d\n", &acct);
  30.  
  31. /*?why will it not proceed to next step without entering the account number 2 times?*/
  32.  
  33. printf ("\Please choose an option below\n");
  34. printf ("\t1. Credit\n");
  35. printf ("\t2. Debit\n");
  36. printf ("Please enter your choice: \n");
  37.  
  38. /*?Prints menu (at this point 2 times) then the program stops, why will it not go to my if else statements?*/
  39.  
  40. if (choice = 1)
  41. printf ("Input CR\n");
  42. else if (choice = 2)
  43. printf ("Input DB\n");
  44. else if (choice != 1, 2)
  45. printf ("\Please choose an option below\n");
  46. printf ("\t1. Credit\n");
  47. printf ("\t2. Debit\n");
  48. printf ("Please enter your choice: \n");
  49. break;
  50.  
  51. }
  52.  
  53. /*do sum of 31 days here*/
  54.  
  55. return 0;
  56. }
Last edited by MeBjess; Oct 12th, 2009 at 4:27 pm. Reason: Include more info
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 392
Reputation: StuXYZ is a glorious beacon of light StuXYZ is a glorious beacon of light StuXYZ is a glorious beacon of light StuXYZ is a glorious beacon of light StuXYZ is a glorious beacon of light StuXYZ is a glorious beacon of light 
Solved Threads: 72
StuXYZ StuXYZ is offline Offline
Posting Whiz
 
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 \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
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 1,678
Reputation: Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all 
Solved Threads: 263
Lerner Lerner is offline Offline
Posting Virtuoso
 
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
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 7
Reputation: MeBjess is an unknown quantity at this point 
Solved Threads: 0
MeBjess MeBjess is offline Offline
Newbie Poster
 
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.
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC