Mọi người giúp em xem lỗi ở đâu được ko ạ? có cứ bị crash giữa chương trình mà em không biết sửa
#include<stdio.h>
#include<stdlib.h>
#include <stdbool.h>
#include<string.h>
#include<conio.h>
bool isValidYN(char * letter)
{
if(letter=='y'||letter=='n')
return true;
else
return false;
}
bool isValidNumber(char * string)
{
for(int i = 0; i < strlen( string ); i ++)
{
if (string[i] < 48 || string[i] > 57)
return false;
}
return true;
}
struct acc
{
char name[100];
float income, nGift, nDependant, tax, taxable, nPen, nIns, code, acc_number, net;
};
void display_options();
void acc_create();
void acc_display();
struct acc account[20];
float num_acc;
int main()
{
char option;
num_acc=0;
while(1)
{
display_options();
printf("Enter your choice: ");
option = getch();
switch(option)
{
case '1':
acc_create();
break;
case '2':
acc_display();
break;
case '3':
return 0;
default :
system("cls");
break;
}
}
}
void display_options()
{
printf("\nChoose one of these following options: \n");
printf("1. Enter a list of employee \n");
printf("2. Display tax information \n");
printf("3. Search an employee buy code \n");
printf("0. Exit \n");
}
void acc_create()
{
int acc_number;
float nIncome, nGift, nDependant, nCode, nPen, nIns, tax, taxable, net;
char name[50], income[50], pension, health, dependant[5], gift[50], code[5];
fflush(stdin);
printf("\nEnter personal information: \n");
printf("Enter your code: ");
start1:
scanf("%s", &code);
if(!(isValidNumber(code)))
{
printf("Invalid input, re-enter: \n");
goto start1;
}
nCode=atof(code);
printf("Enter your name: ");
scanf("%s", &name);
start2:
printf("Income for the current month (in thounsand VND): ");
scanf("%s", &income);
if(!(isValidNumber(income)))
{
printf("Invalid input, re-enter: \n");
goto start2;
}
nIncome=atof(income);
start3:
printf("Pension contributions (5%) y/n?: ");
scanf("%s", &pension);
if(!(isValidYN(pension)))
{
printf("Invalid input, re-enter: \n");
goto start3;
}
if(pension=='y')
nPen=nIncome*0.05;
else
nPen=0;
start4:
printf("Health Insurance (1%) y/n?: ");
scanf("%s", &health);
if(!(isValidYN(health)))
{
printf("Invalid input, re-enter: \n");
goto start4;
}
if(health=='y')
nIns=nIncome*0.01;
else
nIns=0;
start5:
printf("Number of dependants < 18 years old: ");
scanf("%s", &dependant);
nDependant=atof(dependant);
if(!(isValidNumber(dependant)))
{
printf("Invalid input, re-enter: \n");
goto start5;
}
start6:
printf("Gift of charity: ");
scanf("%s", &gift);
nGift=atof(gift);
if(!(isValidNumber(gift))||nGift>nIncome)
{
printf("Invalid input, re-enter: \n");
goto start6;
}
float value=nIncome-(4000+nIncome*0.05+nIncome*0.01+nDependant*1600+nGift);
if(value<=500)
tax=value*0.05;
if(500<value<=1000)
tax=value*0.1;
if(1000<value<=2000)
tax=value*0.15;
if(2000<value<=3000)
tax=value*0.2;
if(3000<value<=5000)
tax=value*0.25;
if(5000<value<=8000)
tax=value*0.3;
if(8000<value)
tax=value*0.35;
//nó bị crash sau đoạn này
strcpy(account[acc_number-1].name,name);
account[acc_number-1].code=nCode;
account[acc_number-1].income=nIncome;
account[acc_number-1].nPen=nPen;
account[acc_number-1].nIns=nIns;
account[acc_number-1].nDependant=nDependant;
account[acc_number-1].nGift=nGift;
account[acc_number-1].taxable=value;
account[acc_number-1].tax=tax;
account[acc_number-1].net=nIncome-tax;
account[acc_number-1].acc_number=acc_number;
}
void acc_display()
{
register int num_acc = 0;
while(strlen(account[num_acc].name)>0)
{
printf("Code : %f \n" ,account[num_acc].code);
printf("Name : %f \n" ,account[num_acc].name);
printf("Income: : %f \n" ,account[num_acc].income);
printf("Pens : %f \n" ,account[num_acc].nPen);
printf("Ins : %f \n" ,account[num_acc].nIns);
printf("Depend : %f \n" ,account[num_acc].nDependant*1600);
printf("Charity : %f \n\n" ,account[num_acc].nGift);
printf("Taxable : %f \n\n" ,account[num_acc].taxable);
printf("Tax : %f \n\n" ,account[num_acc].tax);
printf("Net : %f \n\n" ,account[num_acc].income-account[num_acc].tax);
num_acc++;
}
}