GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 16-Nov-2006, 17:44
yabud yabud is offline
New Member
 
Join Date: Nov 2006
Posts: 6
yabud is on a distinguished road
Question

BOOKEEPING program, HELP!!


Hey everyone, i have to write a program that does the following. I know basic C language but i obviously need more to write this program. If someone could help me out it would be most appreciated. Here are the program specs:

You are to write a very basic bookkeeping program that allows the user to enter a series of transactions and to display both a general journal and a balance sheet.

Your program identifies account numbers from 1000 to 1999 as asset accounts, from 2000 to 2999 as liability accounts, and from 3000 to 3999 as equity accounts.

Your program displays a menu that offers the user four options:

* enter a transaction
* view the general journal
* view the balance sheet
* quit the program

If the user chooses to enter a transaction, then your program prompts the user for

* an account number (between 1000 and 3999)
* the transaction type - whether the transaction is a debit or a credit
* the amount of the transaction (always a positive number)

If the user enters the account number for the very first time, your program adds the new account to the chart of accounts. Once the user has entered the transaction details, your program returns to the menu.

If the user chooses to view the general journal, then your program displays all transactions that have been entered, in the order entered. The format of the general journal is as follows:

General Journal
Account Description Debit Credit
------- ------------------------------ ---------- ----------
1400 3500.00
2100 3500.00
1000 3000.00
1100 1000.00
1400 2000.00
3100 4000.00
3200 2000.00
1000 2100.99
1300 2100.99


There are 30 blank spaces for each transaction description.

If the user chooses to display the balance sheet, then your program displays the balances for all accounts for which transactions have been entered. Your program calculates each account balance by starting at zero and accumulating for that account the amount from each transaction in the general journal. The format for the balance sheet is as follows:

Balance Sheet
Account Description Debit Credit
------- ------------------------------ ---------- ----------
1400 1500.00
1000 899.01
1100 1000.00
1300 2100.99
---------- ----------
Total Assets 5500.00

2100 3500.00
---------- ----------
Total Liabilities 3500.00

3100 4000.00
3200 2000.00
---------- ----------
Total Equity 2000.00
---------- ----------
Total Liabilities and Equity 5500.00


There are 30 blank spaces for each account description.

Note the subtotals for the account types - assets, liabilities and equity - and the sum of the liability and equity accounts.

You may assume a maximum of 20 transactions and a maximum of 10 different accounts. These limits will allow you to display each of the general journal and the balance sheet on a 24-line screen.

Your program allows for gaps in the account numbering, has good error checking, and prompts the user to re-enter unacceptable data (such as non-numeric input for numeric fields or account numbers outside the range 1000-3999). Your program is also well modularized, well commented and readily open to changes in the account type ranges, the maximum number of transactions and the maximum number of accounts.

PS i know the chart formatting is all messed up but you get the deal.
  #2  
Old 16-Nov-2006, 18:06
yabud yabud is offline
New Member
 
Join Date: Nov 2006
Posts: 6
yabud is on a distinguished road

Re: BOOKEEPING program, HELP!!


here is my code thus far

CPP / C++ / C Code:
#include <stdio.h>
#define ACCOUNT_MIN 1000
#define ACCOUNT_MAX 3999

main ()
{
   int account_number, choice;
   char trans_type;
   double trans_amount;
   double debits[20], credits[20]
   while (choice != 4)
   {
      printf("1. Enter a Transaction "); 
      printf("2. View the General Journal ");
      printf("3. View the Balance Sheet ");
      printf("4. Quit the Program ");
      scanf("%d", &choice);
      if (choice == 1)
      {
         printf("Enter an account number (between 1000 and 3999) :");
         scanf("%lf", &account_number);
         while (account_number < ACCOUNT_MIN || account_number > ACCOUNT_MAX)
            {
            printf("Invalid Entry");
            printf("Enter an account number (between 1000 and 3999) :"); 
            scanf("%lf", &account_number);
            }
         printf("Enter the transaction type (d) for debit and (c) for credit: ");
         scanf("%c", &trans_type);
         while (trans_type != 'c' || trans_type != 'd')
         {
            printf("Invalid Entry");
            printf("Enter the transaction type (d) for debit and (c) for credit: ");
            scanf("%c", &trans_type);
         }
         printf("Enter the amount of the transaction (must be positive: ");
         scanf("%lf", &trans_amount);
         while (trans_amount < 0)
         {
            printf("Invalid Entry");
            printf("Enter the amount of the transaction (must be positive): ");
            scanf("%lf", &trans_amount);
         }   
}  
      /*if (choice == 2)
      {
        
      }     
      if (choice == 3)
            
   printf("Ended Program... HAVE A GOOD DAY!!!"); */
}
Last edited by LuciWiz : 17-Nov-2006 at 10:50. Reason: Please insert your C/C++ code between [cpp] & [/cpp] tags
  #3  
Old 16-Nov-2006, 18:57
mathematician mathematician is offline
Member
 
Join Date: Nov 2006
Location: Shrewsbury Uk
Posts: 131
mathematician will become famous soon enough

Re: BOOKEEPING program, HELP!!


Your variables such as account_number, trans_type, trans_amount etc should really be in a structure. You can then write the whole thing out to a file for later retrieval.

Then later, having read the record(s) back into a structure, or array of structures, you will be able to do whatever calculations are necessary in order to present a journal or balance sheet to the user.

The memory for the structures would best be allocated dynamically with the malloc or calloc function.
  #4  
Old 16-Nov-2006, 19:02
HACKin HACKin is offline
New Member
 
Join Date: Nov 2006
Posts: 4
HACKin is on a distinguished road

Re: BOOKEEPING program, HELP!!


hey man i helped you out a little,

in your code you forgot a couple things.

First of all, make sure that you flush the buffer using the fflush(stdin); statement, which i added to the first of your scanfs.

Second of all, your problem with the credit or debit checker is a logic problem.

think of it in english, if trans_type is not equal to 'c' or if trans_type is not equal to 'd' then do this...
which means that the statement can never be false! even if you enter 'c' or 'd' as an answer, the opposite will hold true.

so even if you pick credit, it not equal to d, so the statement is true.

i switched the or to an and (|| to &&) and it worked perfectly.

I made it look a little bit better XD.

heres your code:

CPP / C++ / C Code:
#include <stdio.h>
#include <stdlib.h>
#define ACCOUNT_MIN 1000
#define ACCOUNT_MAX 3999

main ()
{
int account_number, choice;
char trans_type;
double trans_amount;
double debits[20], credits[20];
while (choice != 4)
{
printf("1. Enter a Transaction\n"); 
printf("2. View the General Journal\n");
printf("3. View the Balance Sheet\n");
printf("4. Quit the Program:");
scanf("%d", &choice);
if (choice == 1)
{
printf("Enter an account number (between 1000 and 3999) :");
scanf("%d", &account_number);
fflush(stdin);
while (account_number < ACCOUNT_MIN || account_number > ACCOUNT_MAX)
{
printf("Invalid Entry");
printf("Enter an account number (between 1000 and 3999) :"); 
scanf("%d", &account_number);
fflush(stdin);
}
printf("Enter the transaction type (d) for debit and (c) for credit: ");
trans_type=getchar();
fflush(stdin);
while (trans_type != 'c' && trans_type != 'd')
{
printf("Invalid Entry");
printf("\nEnter the transaction type (d) for debit and (c) for credit: ");
trans_type=getchar();
fflush(stdin);
}
printf("Enter the amount of the transaction (must be positive): ");
scanf("%lf", &trans_amount);
while (trans_amount < 0)
{
printf("Invalid Entry");
printf("\nEnter the amount of the transaction (must be positive): ");
scanf("%lf", &trans_amount);
}
}
/*if (choice == 2)
{

} 
if (choice == 3)

printf("Ended Program... HAVE A GOOD DAY!!!"); */
}
}

see yazz,

HACKin
Last edited by LuciWiz : 17-Nov-2006 at 10:51. Reason: Please insert your C/C++ code between [cpp] & [/cpp] tags
  #5  
Old 16-Nov-2006, 19:03
yabud yabud is offline
New Member
 
Join Date: Nov 2006
Posts: 6
yabud is on a distinguished road

Re: BOOKEEPING program, HELP!!


I am still at a very basic level of C programming so i need more information if thats possible. some examples perhaps. Thanks alot.
  #6  
Old 16-Nov-2006, 19:03
mathematician mathematician is offline
Member
 
Join Date: Nov 2006
Location: Shrewsbury Uk
Posts: 131
mathematician will become famous soon enough

Re: BOOKEEPING program, HELP!!


Personally, if I was writing a book keeping program, I would also want to keep a record of what the transaction was for, and who the buyer/seller was. Those details would also be included in your structure of course.
  #7  
Old 16-Nov-2006, 19:08
HACKin HACKin is offline
New Member
 
Join Date: Nov 2006
Posts: 4
HACKin is on a distinguished road

Re: BOOKEEPING program, HELP!!


well i didnt expand on what you needed to do, i just fix your orignal code.

you just didnt clear the stdin buffer that the OS uses. When you use scanf, it doesnt remove the enter keypress from the input, so its stuck there in the buffer still. of course when you read into your variable it removes the enter keypress, but the next input operation will automaticlly pass on because of that annoying enter XD
  #8  
Old 16-Nov-2006, 19:13
mathematician mathematician is offline
Member
 
Join Date: Nov 2006
Location: Shrewsbury Uk
Posts: 131
mathematician will become famous soon enough

Re: BOOKEEPING program, HELP!!


Ok, here's a structure definition:

typedef struct {

int account_number;
int trans_type;
float trans_amount;
char details[50]; //for office chairs, new PC, etc.
char custsel[ 50 ]; //name of buyer or seller

} RECORD;

Now declare a variable of type RECORD, and for each transaction store the data in that variable (structure) before writing it out to a file with the fwrite function, and, later, reading them back in with the fread function.
  #9  
Old 16-Nov-2006, 20:45
yabud yabud is offline
New Member
 
Join Date: Nov 2006
Posts: 6
yabud is on a distinguished road

Re: BOOKEEPING program, HELP!!


hey, okay so my real problem is that i dont know what to do with the user input when i collect it.... say the user tells me its account number 1900, its a debit , and its value is 4500..... i dont know how to go about accepting these values and placing them properly in a the chart. I need to be able to do this with multiple entries... im totally lost!
  #10  
Old 16-Nov-2006, 23:38
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,242
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all

Re: BOOKEEPING program, HELP!!


Quote:
Originally Posted by HACKin
well i didnt expand on what you needed to do, i just fix your orignal code.

you just didnt clear the stdin buffer that the OS uses. When you use scanf, it doesnt remove the enter keypress from the input, so its stuck there in the buffer still. of course when you read into your variable it removes the enter keypress, but the next input operation will automaticlly pass on because of that annoying enter XD
Problem is you did it wrong. See this

And you all need to read the Guidelines, especially #1.
__________________

Age is unimportant -- except in cheese
 
 

Recent GIDBlogMeeting the local Iraqis by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Pipeline freeze simulation darklightred C++ Forum 6 27-Jul-2006 19:37
How to read particular memory location ? realnapster C Programming Language 10 10-May-2006 09:11
creating a file in [c] i hate c C Programming Language 15 21-Nov-2005 12:52
Type casts ? kai85 C++ Forum 12 23-Jun-2005 12:04
fltk-2.0 cvs Plumb FLTK Forum 20 13-Nov-2004 07:10

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 20:47.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.