homework help

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
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

homework help

 
0
  #1
Nov 8th, 2009
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. }
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 2,046
Reputation: Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of 
Solved Threads: 178
Aia's Avatar
Aia Aia is offline Offline
Postaholic
 
1
  #2
Nov 9th, 2009
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.
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
  #3
Nov 9th, 2009
Thank you! It is so easy to over look the simple things sometimes.
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC