Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
Old Dec 4th, 2004, 11:57 PM   #1
Benoit
Expert Programmer
 
Benoit's Avatar
 
Join Date: Sep 2004
Location: Ontario, Canada
Posts: 579
Rep Power: 5 Benoit is on a distinguished road
I'm bored so I decided to create an accounting program based on what I learned so far in accounting class...it seems to work so far except for one thing, and I can't figure out whats causing it.....


#include<stdio.h>
#include<string.h>

#define MAX 40 //maximum number of accounts

typedef struct
{
	char name[50];
	float balance; 
	
}account;

account assets[MAX];  
int assets_number=0; //set the number of accounts for each to zero

account liabilities[MAX];
int liabilities_number=0;

account expenses[MAX];
int expenses_number=0;

account revenue[MAX];
int revenue_number=0;

account ownersequity[MAX];
int ownersequity_number=0;



void load();
void save();
void add();
void delete();
void balance_sheet();
void income_statement();

main()
{
char choice;

while(choice !='X')
{

	printf("\n\nAccounting database\n\n");
	printf("L: Load an existing set of accounts\n");
	printf("S: Save current accounts\n");
	printf("C: Create new accounts\n");
	printf("D: Delete an account\n");
	printf("X: Exit\n");
	printf("\n\nEnter your choice: ");

	scanf("%c", &choice);

	choice=toupper(choice);

	switch (choice)
	{
	case 'L': load();
 break;
	case 'S': save();
 break;
	case 'C': add();
 break;
	case 'D': delete();
 break;
	case 'X': exit(0);

	default: puts("Not an option");
 break;
	}
}
return 0;
}

void add()
{

char choice;
	
while(choice !='M')
{
	
	printf("\n\nAdd new accounts\n\n");
	printf("A: Asset\n");
	printf("L: Liability\n");
	printf("O: Owner's Equity\n");
	printf("E: Expense\n");
	printf("R: Revenue\n");
	printf("M: Main menue\n\n");
	printf("Enter your choice: ");

	scanf("%c", &choice);

	choice=toupper(choice);

	switch (choice)
	{
	case 'A': 
 assets_number++;
 printf("\nNew asset account name: ");
 scanf("%s", &assets[assets_number].name);
 printf("%s balance: ",assets[assets_number].name);
 scanf("%f", &assets[assets_number].balance);
 break;
	
	case 'L': 
 liabilities_number++;
 printf("\nLiability account name:");
 scanf("%s", &liabilities[liabilities_number].name);
 printf("%s balance: ",liabilities[liabilities_number].name);
 scanf("%f", &liabilities[liabilities_number].balance);
 break;
	case 'O':
 ownersequity_number++;
 printf("\nNew owner's equity account name: ");
 scanf("%s", &ownersequity[ownersequity_number].name);
 printf("%s balance: ",ownersequity[ownersequity_number].name);
 scanf("%f", &ownersequity[ownersequity_number].balance);
 break;

	case 'E': 
 expenses_number++;
 printf("\nNew expense account name: ");
 scanf("%s", &expenses[expenses_number].name);
 printf("%s balance: ",expenses[expenses_number].name);
 scanf("%f", &expenses[expenses_number].balance);
 break;

	case 'R':
 revenue_number++;
 printf("\nNew revenue account name: ");
 scanf("%s", revenue[revenue_number].name);
 printf("%s balance: ",revenue[revenue_number].name);
 scanf("%f", &revenue[revenue_number].balance);
 break;

	case 'M': break;

	
	
	} 

}
}


void load()
{
//nothing here yet
}


void save()
{
//nothing here yet
}


void delete()
{
//nothing here yet
}

As you can see its incomplete so far, but I tried testing out what I have so far to make sure it works and I get this output:

Accounting database

L: Load an existing set of accounts
S: Save current accounts
C: Create new accounts
D: Delete an account
X: Exit


Enter your choice: c


Add new accounts

A: Asset
L: Liability
O: Owner's Equity
E: Expense
R: Revenue
M: Main menue

Enter your choice:

Add new accounts

A: Asset
L: Liability
O: Owner's Equity
E: Expense
R: Revenue
M: Main menue

Enter your choice:


For some reason, it prints the menu for the add accounts section twice :wacko:
__________________
Johnny was a chemist's son but Johnny is no more, for what Johnny thought was H2O was H2SO4
Benoit is offline   Reply With Quote
 

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 10:55 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC