BOOKKEEPING program - need help its urgent ......

This is a discussion on BOOKKEEPING program - need help its urgent ...... within the C Programming forums, part of the General Programming Boards category; You may assume a maximum of 20 transactions and a maximum of 10 different accounts......... i am trying to do ...

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    9

    Exclamation BOOKKEEPING program - need help its urgent ......

    You may assume a maximum of 20 transactions and a maximum of 10 different accounts.........


    i am trying to do this part but its not working

    Code:
    #define MAX_ACCOUNTS  10
    main(){
    ................................
    .........................
    }
    
    .................
     if (AccountNumber[MAX_ACCOUNTS]>MAX_ACCOUNTS+1){
            printf("  **Maximum number of accounts has been entered\n");
            main();
        }

    its a same Q. as some1 has already post by the name of "BOOKKEEPING PROGRAM, need help! "..........if sum1 can help , i wud b so grateful ........thanx
    Last edited by Salem; 11-19-2006 at 02:23 PM. Reason: Remove comic font abuse

  2. #2
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    We won't do your homework for you. Write a good try and then come to us with actual problems, not just a plea for homework.
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  3. #3
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    main is entry point of the C-program, it is call automatically when program starts.
    On most compilers you cannot call it from your code. Use another name
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  4. #4
    Registered User
    Join Date
    Nov 2006
    Posts
    9

    Exclamation

    I did made an effort ......... this is my code so far .......just having sum problem wid validation n stuff .............if u guyz can help .....???


    Code:
    #include <stdio.h>
    #define MAX_ACCOUNTS   10
    #define MAX_TRANS      20
    #define MAX_ITEMS      41
    
    int AccountNumber[MAX_ACCOUNTS];
    char TransactionType[MAX_TRANS];
    double TransactionAmount[MAX_ITEMS];
    
    int options(void);
    int input(int counter);
    int journal(int counter);
    int balancesheet(int counter);
    double equity(int credit, double totalequity, double TransactionAmount, int AccountNumber);
    void clear();
    
    main(){
    	int menu=0,quit=0,counter=0;
        while(quit==0) {
    	menu=options();
    	    if(menu==1){
    			quit=input(counter);
    			counter=counter+1;
    		}else if (menu==2){
    			quit=journal(counter);
    		}else if (menu==3){
    			balancesheet(counter);
            }else
    	     quit=1;
      }clear();
    }
    int options(void){
    	int selectedoption=0,keeptrying=1,rc;
    	char after;
    	printf("\n");
    	printf(" Options available: \n\n");
    	printf("  1 - Enter a transaction\n  2 - View the general ledger\n  3 - View the balance sheet\n  q - Quit the program\n\n Please enter 1, 2, 3, or q: ");
    	do{
                 rc=scanf("%d%c",&selectedoption,&after);
                 if(rc==0){
                     printf("  **Invalid input\n  **Please reenter : ");
                     clear();
                  }else if(after!='\n'){
                        printf("  **Trailing character encountered\n  **Please reenter : ");
                  }else if (selectedoption<=0){
                        printf("  **Invalid input\n  **Please reenter : ");
                        clear();
                  }else 
                        keeptrying=0;
                  }while(keeptrying==1);
                  return selectedoption;
    }
    int input(int counter){
        int rc;
        char after;
    	printf("\n Enter an account number (between 1000 and 3999) : ");
        /* Account Number validation */
        while(AccountNumber[counter]<=999||AccountNumber[counter]>3999||after!='\n'||rc==0){
              rc=scanf("%d%c",&AccountNumber[counter],&after);
              if(rc==0){
                     printf("  **Invalid input\n  **Please reenter : ");
                     clear();
              }else if(AccountNumber[counter]<=999 || AccountNumber[counter]>3999){
                    printf("  **Out of range\n  **Please reenter : ");
              }else if(after!='\n'){
                    printf("  **Trailing character encountered\n  **Please reenter : ");
                    clear();
              }
        }
        if (AccountNumber[MAX_ACCOUNTS]>MAX_ACCOUNTS+2){
            printf("  **Maximum number of accounts has been entered\n");
            main();
        }
    	printf("\n Enter d (debit) or c (credit): ");
    	/* Debit/Credit validation */
    	while (TransactionType[counter] != 'C' && TransactionType[counter] != 'c' &&TransactionType[counter] != 'D' && TransactionType[counter] != 'd' ||after!='\n'){
    	  scanf (" %c%c", &TransactionType[counter],&after);
    	  if(TransactionType[counter] != 'C' && TransactionType[counter] != 'c' &&TransactionType[counter] != 'D' && TransactionType[counter] != 'd'){
               printf("  **Invalid input\n  **Please reenter : ");
          }else if(after!='\n'){
               printf("  **Trailing character encountered\n  **Please reenter : ");
          }
       }
       if(TransactionType[MAX_TRANS+1]>MAX_TRANS){
            printf("  **Maximum number of transactions has been entered\n");
            main();
       }
    	printf("\n Enter transaction amount: ");
    	Validation(counter);
    }
    /**********************Transaction Amount validation *************************/
    int Validation (int counter){
        int rc;
        char after;
        while (TransactionAmount[counter] < 0||after!='\n'||rc==0){
              scanf ("%lf%c", &TransactionAmount[counter],&after);
                if(after!='\n'){
                   printf("  **Trailing character encountered\n  **Please reenter : ");
                   clear();
               }else if(rc==0){
                   printf("  **Invalid input\n  **Please reenter : ");
               }else if(TransactionAmount[counter]<0){
    	           printf("  **Out of range\n  **Please reenter : ");
               }
         }return 0;  
    }
    /***************************************/
    int journal(int counter){
    	int counter2=0;
    	printf("\n\n                         General Journal                     \n");
    	printf(" Account Description                         Debit     Credit \n");
    	printf(" ------- ------------------------------ ---------- ---------- \n");
    	for (counter2=0; counter2<counter; counter2=counter2+1){
    		if(TransactionType[counter2] == 'c' || TransactionType[counter2] == 'C'){
    			printf("%8d%53.2lf\n", AccountNumber[counter2], TransactionAmount[counter2]);
    	    } else if (TransactionType[counter2] == 'd' || TransactionType[counter2] == 'D'){
    			printf("%8d%42.2lf\n", AccountNumber[counter2], TransactionAmount[counter2]);
    		}
    	}
    return 0;
    }
    int balancesheet(int counter){
    	int counter2=0, counter3=0, check[MAX_ITEMS]={0},credit=0;
    	double totalassets=0.0, subassets=0.0, totalliabilities=0.0,subliabilities=0.0,totalequity=0.0,subequity=0.0,totalLiabilitiesEquity=0.0;
    	printf("\n                         Balance Sheet                       \n");
    	printf(" Account Description                         Debit     Credit \n");
    	printf(" ------- ------------------------------ ---------- ---------- \n");
    	for (counter2=0; counter2<counter; counter2=counter2+1){
    		subassets=TransactionAmount[counter2];
    		if(AccountNumber[counter2]<= 1999 && check[counter2]== 0){
    			check[counter2]=1;
    			for(counter3=counter2+1; counter3<= counter; counter3=counter3+1){
    				if(AccountNumber[counter2]==AccountNumber[counter3] && check[counter3]==0){
    					check[counter3]=1;
    					if(TransactionType[counter3]=='c' || TransactionType[counter3]=='C'){
    						subassets=subassets-TransactionAmount[counter3];
    				    }else if(TransactionType[counter3]=='d' || TransactionType[counter3]=='D'){
    					    subassets=subassets+TransactionAmount[counter3];
    				    }
    			    }
    		    }
    		    printf("%8d%42.2lf\n", AccountNumber[counter2], subassets);
    		    totalassets=totalassets+subassets;
    		}
    	}
    	printf("                                        ---------- ---------- \n");
    	printf("             Total Assets                  %7.2lf\n",totalassets);
    	for(counter2=0;counter2<= counter; counter2=counter2+1){
    		subliabilities=TransactionAmount[counter2];
    		if (AccountNumber[counter2] <= 2999 && AccountNumber[counter2] >=2000 && check[counter2]==0){
    			check[counter2]=1;
    			for(counter3=counter2+1; counter3<= counter; counter3=counter3+1){
    				if(AccountNumber[counter2]==AccountNumber[counter3] && check[counter3]== 0){
    					check[counter3]=1;
    					if(TransactionType[counter3]=='c' || TransactionType[counter3]=='C'){
    						subliabilities=subliabilities-TransactionAmount[counter3];
    					}else if(TransactionType[counter3]=='d' || TransactionType[counter3]=='D'){
    						subliabilities=subliabilities+TransactionAmount[counter3];
    					}
    				}
    			}
    			if(subliabilities > 0){
    				printf("\n\n%8d%53.2lf",AccountNumber[counter2],subliabilities);
    				totalliabilities=totalliabilities + subliabilities;
    			}else if (subliabilities < 0){
    				totalliabilities=totalliabilities + subliabilities;
    				printf("\n\n%8d%53.2lf",AccountNumber[counter2],subliabilities);
    			}
    	    }
         }
    	printf("\n                                        ---------- ---------- \n");
    	printf("             Total Liabilities                        %7.2lf\n",totalliabilities);
    
    	for(counter2=0; counter2 <= counter; counter2=counter2+1){
    		subequity=TransactionAmount[counter2];
    		if(AccountNumber[counter2] <= 3999 && AccountNumber[counter2] >= 3000 && check[counter2]==0){
    			check[counter2]=1;
    			credit=4;
    			for(counter3=counter2+1; counter3<= counter; counter3=counter3+1){
    				if(AccountNumber[counter2] == AccountNumber[counter3] && check[counter3]== 0){
    					check[counter3] = 1;
    					if(TransactionType[counter3]=='c' || TransactionType[counter3]=='C'){
    						subequity=subequity + TransactionAmount[counter3];
    						credit=3;
    					}else if(TransactionType[counter3]=='d' || TransactionType[counter3]=='D'){
    						subequity=subequity - TransactionAmount[counter3];
    						credit=3;
    					}
    				}
    			}
    			if(TransactionType[counter2]=='c' || TransactionType[counter2]=='C' && credit == 4){
    				printf("\n%8d%53.2lf",AccountNumber[counter2],TransactionAmount[counter2]);
    				totalequity=totalequity + TransactionAmount[counter2];
    				credit=0;
    			}else if (TransactionType[counter2]=='d' || TransactionType[counter2]=='D' && credit == 4){
    				printf("\n%8d%42.2lf",AccountNumber[counter2],TransactionAmount[counter2]);
    				totalequity=totalequity - TransactionAmount[counter2];
    				credit=0;
    			}
    		}
        }
    		printf("\n                                        ---------- ---------- \n");
    		if(totalequity < 0){
    			totalequity = totalequity * -1;
    			printf("             Total Equity                             %7.2lf\n",totalequity);
    		}else {
    			printf("             Total Equity                             %7.2lf\n",totalequity);
    		}
    		printf("                                        ---------- ---------- \n");
    		totalLiabilitiesEquity=totalequity + totalliabilities;
    		printf("             Total Liabilities and Equity             %7.2lf\n",totalLiabilitiesEquity);
    
    }
    void clear(void){
         while ( getchar() != '\n' );
    }

  5. #5
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    1) Indentation, indentation, indentation.
    2)
    Code:
    if (AccountNumber[MAX_ACCOUNTS]>MAX_ACCOUNTS+2)
    
    This is a out-of-bounds error.
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  6. #6
    Registered User
    Join Date
    Nov 2006
    Posts
    9
    Code:
    what is wrong with indentation in it :( .........can u help plz ?

  7. #7
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    Sample:
    Code:
    while(quit==0) {
    	menu=options();
    	    if(menu==1){
    			quit=input(counter);
    			counter=counter+1;
    		}else if (menu==2){
    			quit=journal(counter);
    		}else if (menu==3){
    			balancesheet(counter);
            }else
    	     quit=1;
      }
    This is quite confusing. This is better (my style):
    Code:
    while(quit==0) 
    {
          menu=options();
          if(menu==1)
          {
    	quit=input(counter);
    	counter=counter+1;
          }
          else if (menu==2)
          {
       	quit=journal(counter);
          }
          else if (menu==3)
          {
    	balancesheet(counter);
          }
          else
    	quit=1;
      }
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  8. #8
    Registered User
    Join Date
    Nov 2006
    Posts
    9
    Our professor want it that way .........

    can u help wid the Max . account numbers stuff ?........if u can plz .......

  9. #9
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    Read my second comment.
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  10. #10
    Registered User
    Join Date
    Nov 2006
    Posts
    9
    OK thank you very much ..........

  11. #11
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    Does it now work?
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  12. #12
    Registered User
    Join Date
    Nov 2006
    Posts
    9

    Exclamation

    No, it doesnot :S ...... but i dont think i'll get any kind ov help ........so, gonna try again..................

  13. #13
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    Try debuging and tell us on what line the error is.
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  14. #14
    Registered User
    Join Date
    Nov 2006
    Posts
    9
    this is how my output shud luk lyk .....but it gves me a an error message after "Enter an account number (between 1000 and 3999) : 3999" and i want it after "Enter an account number (between 1000 and 3999) : 3998"..............& last thing is this that ....it should start count account numbers all over again .....but wid my code it doesnot ....... .........so any1 can debug it ..........plzzzz.................

    Code:
    .................................................
    Enter d (debit) or c (credit): d
    
    Enter transaction amount: 9000
    
    Options available:
    
     1 - Enter a transaction
     2 - View the general ledger
     3 - View the balance sheet
     q - Quit the program
    
    Please enter 1, 2, 3, or q: 1
    
    Enter an account number (between 1000 and 3999) : 3999
    
    Enter d (debit) or c (credit): d
    
    Enter transaction amount: 10000
    
    Options available:
    
     1 - Enter a transaction
     2 - View the general ledger
     3 - View the balance sheet
     q - Quit the program
    
    Please enter 1, 2, 3, or q: 1
    
    Enter an account number (between 1000 and 3999) : 3998
     **Maximum number of accounts has been entered
    
    Options available:
    
     1 - Enter a transaction
     2 - View the general ledger
     3 - View the balance sheet
     q - Quit the program

  15. #15
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    No, the idea is that you're supposed to debug it.
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 01:27 PM
  2. urgent help for this difficult program
    By ptr_ritchie in forum C Programming
    Replies: 1
    Last Post: 04-01-2007, 02:42 AM
  3. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 11:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21