Can anybody take a look at this?
I'm currently trying to write a (small) tax programme and have at last managed to do so, but not without my problems.
My source code appears to be good, but when I run it (in Borland 3.0), the final output gets all screwed up. The code itself is pretty long:
Code:
//Header Files
#include <stdio.h>
#include <string.h>
#include <conio.h>
#include <ctype.h>
#include <stdlib.h>
#include <math.h>
void main() //Main
{
//ABC Ltd. header
printf(" -----------------------------------------------");
printf("\n | |");
printf("\n | ABC COMPANY LTD (MAURITIUS) |");
printf("\n | |");
printf("\n | ANNUAL INCOME TAXES |");
printf("\n | |");
printf("\n -----------------------------------------------");
//Password protection
//Password: neoteric
//Encrypting password
char encrypted[] = "EBuANANatYHcbQvIhAnU";
char password[80];
char unencrypted[] = "abcdefghijklmnopqrst";
int i = 0;
long code = 0;
for(;;)
{
strcpy(unencrypted, "abcdefghijklmnopqrst");
printf("\n\n\nEnter password (max. 20 characters, no spaces): ");
scanf("%s", password);
for( i= 0; i < 20 && password[i] != '\0'; i++)
unencrypted[i] = password[i];
code = 0;
for(i=0; i < 20; code += unencrypted[i++]);
code %= 52;
code += code < 26 ? 'A' : ('a' - 26);
for(i = 0; i < 20; i++)
{
code *= unencrypted[i];
code %= 52;
code += (code < 26) ? 'A': ('a' - 26);
password[i] = (char)code;
}
password[i] = '\0';
//Checking password
if(strcmp(password, encrypted) != 0)
printf("\nAccess denied!\n");
else
{
printf("\nLogged in.\n");
break;
}
}
clrscr(); //Clear screen
printf(" -----------------------------------------------");
printf("\n | |");
printf("\n | ABC COMPANY LTD (MAURITIUS) |");
printf("\n | |");
printf("\n | ANNUAL INCOME TAXES |");
printf("\n | |");
printf("\n -----------------------------------------------");
//Declaration of variables
char title[3];
char surname[60];
char other_names[80];
char maiden_name[60];
char husband_name[100];
char residential_address[120];
char id[14];
char marital_status[1];
char name_spouse[100];
char acc_spouse[8];
char spouse_work[1];
char children[1];
char pensioner[1];
char car_benef[1];
char free_benef[1];
char other_rev[1];
int DOB;
int DOM;
int dept_no[3];
int num_children;
long phone_num_res[7];
long phone_num_off[7];
float basic_sal, total_sal, pension, emoluments, car_benefit, acc;
float others, total_inc, emo_rel, total_relief, dep_child;
float perso_deduc = 70000;
float spouse_deduc = 55000;
float child_deduc = 8000;
//Entry details
textcolor(GREEN);
cprintf("\n\n "
" ENTRY DETAILS");
printf("\n\n\nDepartment No. (3 digits): ");
scanf("%d", &dept_no);
printf("\nTitle (Ms/Mrs/Mr/Ww): ");
scanf("%s", title);
printf("\nSurname: ");
scanf("%s", surname);
printf("\nOther names: ");
scanf("%s", other_names);
//Add maiden name and husband
//name if applicable
if(strnicmp(title, "mrs", 3) == 0)
{
printf("\nMaiden name: ");
scanf("%s", maiden_name);
printf("\nName of husband: ");
scanf("%s", husband_name);
}
//Continue with details
printf("\nResidential address: ");
scanf("%s", residential_address);
getchar();
getchar();
printf("\nDate of birth (DD/MM/YY): ");
scanf("%d", &DOB);
getchar();
getchar();
getchar();
printf("\nID No.: ");
scanf("%s", id);
getchar();
getchar();
printf("\nTelephone No. (Residence): ");
scanf("%ld", &phone_num_res);
getchar();
getchar();
getchar();
printf("\nTelephone No. (Office): ");
scanf("%ld", &phone_num_off);
getchar();
getchar();
//Verifying marital status
if(strnicmp(title, "mr", 3) == 0)
{
printf("\nAre you married? (Y/N): ");
scanf("%s", marital_status);
getchar();
getchar();
}
//Other details for married men only
if(strnicmp(marital_status, "y", 1) == 0)
{
printf("\nFull name of spouse: ");
scanf("%s", name_spouse);
getchar();
getchar();
printf("\nDate of marriage (DD/MM/YY): ");
scanf("%d", &DOM);
getchar();
getchar();
printf("\nTax Account No. of spouse: ");
scanf("%s", &acc_spouse);
getchar();
printf("\nDoes your spouse work? (Y/N): ");
scanf("%s", spouse_work);
}
//Checking for dependent children
printf("\nDo you have any children? (Y/N): ");
scanf("%s", &children);
getchar();
if(strnicmp(children, "y", 1) == 0)
{
printf("\nHow many children?: ");
scanf("%d", &num_children);
getchar();
}
clrscr(); //Clear screen
printf(" -----------------------------------------------");
printf("\n | |");
printf("\n | ABC COMPANY LTD (MAURITIUS) |");
printf("\n | |");
printf("\n | ANNUAL INCOME TAXES |");
printf("\n | |");
printf("\n -----------------------------------------------");
//Requiring input for calculations
cprintf("\n\n "
" FINANCIAL DETAILS");
printf("\n\nBasic salary: Rs ");
scanf("%f", &basic_sal);
getchar();
//Checking for pension
printf("\n\nDo you touch any pension? (Y/N): ");
scanf("%s", pensioner);
if(strnicmp(pensioner, "y", 1) == 0)
{
printf("\n\nPension: Rs ");
scanf("%f", &pension);
getchar();
}
printf("\n\nArrears of emoluments: Rs ");
scanf("%f", &emoluments);
getchar();
//Checking for car benefit
printf("\n\nAre you beneficiary of car benefit? (Y/N): ");
scanf("%s", car_benef);
if(strnicmp(car_benef, "y", 1) == 0)
{
printf("\n\nCar benefit: Rs ");
scanf("%f", &car_benefit);
getchar();
}
//Checking for free accomodation
printf("\n\nAre you beneficiary of free accomodation? (Y/N): ");
scanf("%s", free_benef);
getchar();
if(strnicmp(free_benef, "y", 1) == 0)
{
printf("\n\nFree accomodation: Rs ");
scanf("%f", &acc);
getchar();
}
//Checking for additional income
printf("\n\nDo you get any revenue through other means"
" (contract jobs, business, etc...)? (Y/N): ");
scanf("%s", other_rev);
getchar();
if(strnicmp(other_rev, "y", 1) == 0)
{
printf("\n\nOther revenue: Rs ");
scanf("%f", &others);
getchar();
}
clrscr();
//Determining and displaying
//personal reliefs and deductions
printf("\n\nBasic personal deduction is Rs %f", perso_deduc);
//Dependant spouse deduction where applicable
if(strnicmp(spouse_work, "n", 1) == 0)
{
printf("\nDeduction for dependant spouse is Rs %f", spouse_deduc);
getchar();
}
//Dependant children deduction where applicable
if(strnicmp(children, "y", 1) == 0)
{
dep_child = num_children * child_deduc;
printf("\n\nDeduction for dependent children is Rs %f", dep_child);
getchar();
}
clrscr();
printf(" -----------------------------------------------");
printf("\n | |");
printf("\n | ABC COMPANY LTD (MAURITIUS) |");
printf("\n | |");
printf("\n | ANNUAL INCOME TAXES |");
printf("\n | |");
printf("\n -----------------------------------------------");
//Generating report
cprintf("\n\n "
" FINAL REPORT");
//Displaying all the details
printf("\n\nDepartment No. %d.", dept_no);
getchar();
printf("\n%s %s %s", title, surname, other_names);
getchar();
if(strnicmp(title, "mrs", 3) == 0)
{
printf("\nOf maiden name %s.", maiden_name);
getchar();
printf("\nName of husband is %s.", husband_name);
getchar();
}
printf("\n%s.", residential_address);
getchar();
printf("\nBorn on %d.", DOB);
getchar();
printf("\nNational Identity No. %s.", id);
getchar();
printf("\nHome telephone number: %ld.", phone_num_res);
getchar();
printf("\nOffice telephone number: %ld.", phone_num_off);
getchar();
if(strnicmp(title, "mr", 3) == 0)
{
printf("\nFull name of spouse is Mrs %s.", name_spouse);
getchar();
printf("\nDate of marriage (DD/MM/YY) is %d.", DOB);
getchar();
printf("\nTax Account No. of spouse is %s.", acc_spouse);
getchar();
}
if(strnicmp(children, "y", 1) == 0)
{
printf("\nNumber of dependent children is %d.", num_children);
getchar();
}
//Showing values
printf("\n\nBasic salary is Rs %f", basic_sal);
printf("\n\nEnd-of-year bonus is Rs %f", basic_sal);
//Calculation of total salary for one year
total_sal = (basic_sal * 12) + basic_sal;
printf("\n\nTotal salary is Rs %f", total_sal);
if(strnicmp(pensioner, "y", 1) == 0)
{
printf("\n\nPension received is Rs %f", pension);
}
printf("\n\nArrears of emoluments amount to Rs %f", emoluments);
if(strnicmp(car_benef, "y", 1) == 0)
{
printf("\n\nCar benefit amounts to Rs %f", car_benefit);
}
if(strnicmp(free_benef, "y", 1) == 0)
{
printf("\n\nFree accomodation amounts to Rs %f", acc);
}
if(strnicmp(other_rev, "y", 1) == 0)
{
printf("\n\nOther revenue amounts to Rs %f", others);
}
//Income Tax Calculations
//Displaying results of calculations
//Calculating the total income
total_inc = total_sal + pension + emoluments + car_benefit + acc + others;
printf("\n\nYour total income for this year is Rs %f", total_inc);
getchar();
emo_rel = 0.15 * total_inc;
if(total_inc < 433333.333333)
{
printf("\nEmoluments relief (max. Rs 65000): Rs %f", emo_rel);
getchar();
}
//Total personal reliefs to be
//deducted from net income
total_relief = emo_rel + perso_deduc + spouse_deduc + pension + dep_child;
printf("\n\nTotal personal reliefs and deductions amount to Rs %f"
, total_relief);
if(total_inc > total_relief)
printf("\n\nTax payable for this year is Rs %f", total_inc - total_relief);
getchar();
if(total_inc < total_relief)
printf("\n\nTax to be paid in excess for this year is Rs %f",
total_relief - total_inc);
getchar();
if(total_inc == total_relief)
printf("\n\nExempt of taxes for this year.");
getchar();
//List of documents to be attached
printf("\n\nPlease note that the following documents are required:");
printf("\n\n1. Original of Statement of Emoluments and Tax Deduction;");
printf("\n\n2. Appropriate receipts/certificates for the reliefs and"
" deductions claimed.");
printf("\n\nPayment should be made by crossed cheque payable to"
" the Commissioner of Income Tax.");
printf("\n\nFull name and Tax Account Number are to be written "
"on the verso of the cheque.");
getchar();
getchar();
getchar();
getchar();
}
Does anybody know what's wrong with it?
Criticism and additional comments on how to improve the program are also welcome (I'm still a beginner).