Beruflich Dokumente
Kultur Dokumente
SUBJECT : C PROGRAMMING
How to manipulate C language to code a program that can help user to track their expenditure.
Features of the program :
-Enable the user to enter/select the date to sort their expenditure.
-Able to give the user the output on total expense, total income and balance of a certain time period.
-Provide the user with a list of their expenditure with details such as date and amount.
METHADOLOGY
Begin (main)
While x!=4
Do
x=0
Call function date_selection
Ask user enter the date
Switch
Case 1 until case 12
set the month name to be used for file operation
default
set the month name to “not valid”
While month_name == not valid
Set file name
While x!=3
Read data from file
Call function home _display
Ask user enter the selection
If (x=1)
Ask user enter the amount
Ask user enter the category / description
Total expense = call function sum
Exp. = -exp
Balance = call function sum
Add data to file
If (x=2)
Ask user enter the amount
Ask user enter the category
Total income = call function sum
Balance = call function sum
Add data to file
Display “Exit successful”
End
Begin (date_selection)
Display the date selection menu
End
Begin (home_display)
Display the home menu, balance, total expense, total income
End
Begin (sum)
Sum = n1+n2
End
RESULT
CONCLUSION
The objective of this project is fulfilled. With the uses of pointer , array , user defined data type, string , file
operation, calculation and a few more elements in C language , a program that enable user to track their expenditure is
created.
This program is 100% functioning and satisfied the objective of the project. However, some modification can be
done in the future such as adding a feature where user can determine the time period of output either it is daily,
monthly or yearly. Adding category view feature to the programme also can give the user more option. This modification
can develope the program productivity and flexibility.
In the conclusion, C language can be used to solve many type of problem as long as the algorithm and format is
perfectly correct.
APPENDIX
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void){
setvbuf (stdout, NULL, _IONBF, 0);setvbuf (stderr, NULL, _IONBF, 0);
int x=0, d, m, y;
char day[5], month[5], year[5], month_name1[10], month_name2[30], month_name3[30], month_name4[30];
char *month_fn, *bal_fn, *exp_fn, *inc_fn;
char file_ext[]=".txt", balfile_ext[]="bal.txt", expfile_ext[]="exp.txt", incfile_ext[]="inc.txt";
char arrbal[100], arrexp[100], arrinc[100], desc[100];
double balance, total_expense, total_income;
float expense, income, *pexp, *pinc;
FILE*bal_file;
FILE*exp_file;
FILE*inc_file;
FILE*list_file;
while (x != 4){
strcpy(arrbal, "0.00");strcpy(arrexp, "0.00");strcpy(arrinc, "0.00");
do{
x=0;
date_selection_display ();// call date_selection_display function
scanf ("%d/%d/%d", &d, &m, &y);
itoa (d, day, 10);itoa (m, month, 10);itoa (y, year, 10);
switch (m){
case 1:
strcpy (month_name1,"JAN");strcpy (month_name2,"JAN");
strcpy (month_name3,"JAN");strcpy (month_name4,"JAN");
break;
case 2:
strcpy (month_name1, "FEB");strcpy (month_name2, "FEB");
strcpy (month_name3, "FEB");strcpy (month_name4, "FEB");
break;
case 3:
strcpy (month_name1, "MAR");strcpy (month_name2, "MAR");
strcpy (month_name3, "MAR");strcpy (month_name4, "MAR");
break;
case 4:
strcpy (month_name1, "APR");strcpy (month_name2, "APR");
strcpy (month_name3, "APR");strcpy (month_name4, "APR");
break;
case 5:
strcpy (month_name1, "MAY");strcpy (month_name2, "MAY");
strcpy (month_name3, "MAY");strcpy (month_name4, "MAY");
break;
case 6:
strcpy (month_name1, "JUN");strcpy (month_name2, "JUN");
strcpy (month_name3, "JUN");strcpy (month_name4, "JUN");
break;
case 7:
strcpy (month_name1, "JUL");strcpy (month_name2, "JUL");
strcpy (month_name3, "JUL");strcpy (month_name4, "JUL");
break;
case 8:
strcpy (month_name1, "AUG");strcpy (month_name2, "AUG");
strcpy (month_name3, "AUG");strcpy (month_name4, "AUG");
break;
case 9:
strcpy (month_name1, "SEP");strcpy (month_name2, "SEP");
strcpy (month_name3, "SEP");strcpy (month_name4, "SEP");
break;
case 10:
strcpy (month_name1, "OCT");strcpy (month_name2, "OCT");
strcpy (month_name3, "OCT");strcpy (month_name4, "OCT");
break;
case 11:
strcpy (month_name1, "NOV");strcpy (month_name2, "NOV");
strcpy (month_name3, "NOV");strcpy (month_name4, "NOV");
break;
case 12:
strcpy (month_name1, "DIS");strcpy (month_name2, "DIS");
strcpy (month_name3, "DIS");strcpy (month_name4, "DIS");
break;
default:
strcpy (month_name1, "NOT VALID");
printf ("%s\n", month_name1);
break;
}
}
while (strcmp (month_name1, "NOT VALID") == 0);//compare month name
if (x == 1){
printf
("\n***********************************************************\n\n\n");
printf ("Enter the amount:\n");
scanf ("%f", &expense);
printf ("Enter the category/description:");
scanf ("%s", desc);
printf
("\n\n\n***********************************************************\n");
*pexp = -*pexp;