944,038 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 346
  • C RSS
Nov 8th, 2009
0

homework help

Expand Post »
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.

  1. /*Current Problems which need to be fixed:
  2. Input account number and be able to change the account balance accordingly.
  3. When prompted, display the account balance accordingly.
  4. */
  5.  
  6. #include <stdio.h>
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #include <ctype.h>
  11. #define DAY 2
  12. #define MAXACCT 25
  13.  
  14.  
  15.  
  16. int main(void)
  17. {
  18. printf("Basic Accounting Program\n\n");
  19.  
  20. int acct;
  21. int count, factorial;
  22. int choice = 0;
  23. long credit;
  24. int debit = 0;
  25. int j = 0;
  26. int bal;
  27. /*these are declared from another program, using them as aides in understanding*/
  28. long balance[MAXACCT];
  29. long jacct[MAXACCT];
  30. int thisacct;
  31. int thisamt;
  32. int i;
  33. int foundacnt;
  34. char input[25];
  35. char rtrn;
  36. /*end of items declared from other program*/
  37.  
  38.  
  39.  
  40. for (count = 1; count < DAY ; count++)
  41. {
  42. printf ("Day %d\n\n",count);
  43.  
  44. here1:
  45. printf ("Input account number, thank you!\n");
  46. rtrn = scanf ("%d", &jacct);
  47. here:
  48. printf ("\nPlease choose an option below\n");
  49. printf ("\t1. Credit (Charge Card Transaction: CR)\n");
  50. printf ("\t5. Account Balance\n");
  51. printf ("\t8. Exit\n");
  52. printf ("Please enter your choice: \n");
  53. scanf ("%d", &choice);
  54.  
  55. if (choice == 1)
  56. {
  57. printf ("Input CR\n");
  58. scanf ("%d", &credit);
  59. /*how do i get the credit (money added) to
  60.   be applied to the account?
  61. for example, suppose I choose option 1
  62.   two times, how do I make the first CR add
  63.   to the 2nd CR?*/
  64. bal = 0 + credit;
  65. goto here;
  66. }
  67. else if (choice == 5)
  68. {
  69. printf ("Your account balance is %d\n", bal);
  70. /*how do i save and output the
  71.   adjusted balance?
  72. for example, suppose I entered two CR
  73.   (option 1) transactions, the first time I CR
  74.   the account 5, then 10,
  75. so now I want the balance to say 15.*/
  76. goto here;
  77. }
  78. else if (choice == 8)
  79. {
  80. return (0);
  81. }
  82. else if (choice != 1 || choice != 5 || choice != 8)
  83. {
  84. printf ("OOPS! Invalid Entry!\n");
  85. goto here;
  86. }
  87. here2: ;
  88. }
  89. return 1;
  90. }
Similar Threads
Reputation Points: 12
Solved Threads: 0
Newbie Poster
MeBjess is offline Offline
7 posts
since Oct 2009
Nov 9th, 2009
1
Re: homework help
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.
Aia
Reputation Points: 2224
Solved Threads: 218
Nearly a Posting Maven
Aia is offline Offline
2,304 posts
since Dec 2006
Nov 9th, 2009
0
Re: homework help
Thank you! It is so easy to over look the simple things sometimes.
Reputation Points: 12
Solved Threads: 0
Newbie Poster
MeBjess is offline Offline
7 posts
since Oct 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: adding a character to a string
Next Thread in C Forum Timeline: Help about my program. About files





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC