Hye all. Im new to this forum. I would like to seek some help here.
Below is my source code for counting the net salaray of a worker. My question is, how for example, in the name area, I only want the user to input character, other than that, invalid data and for id only numbers ? And, how at the end of the program, to make the user input only y for continue the program, and n to exit the program.?
Code:
#include <stdio.h>
void main()
{
int id;
char month[100],position[500],name[500],ex;
double basic_salary,EPF_deduction,gross_salary,total_OT_payment,net_salary,OT_rate;
double OT;
OT_rate = 50;
ex = 'y';
do
{
printf("\n\nPlease enter month (Capital Letter): ");
scanf("%s",month);
printf("\n\n*******************************************************************");
printf("\nPAYMENT SLIPS FOR THE MONTH %s 2005\nSMART CHOICE EDUCATION CENTRE\n",month);
printf("*******************************************************************\n");
printf("Staff name\t\t: ");
scanf("%s",&name);
printf("Staff ID\t\t: ");
scanf("%d",&id);
printf("Position\t\t: ");
scanf("%s",&position);
printf("*******************************************************************\n");
printf("\nBasic Salary\t\t: RM ");
scanf("%lf",&basic_salary);
EPF_deduction = basic_salary * 0.1;
printf("EPF Deduction\t\t: RM %.2lf\n",EPF_deduction);
gross_salary = basic_salary - EPF_deduction;
printf("Gross Salary\t\t: RM %.2lf\n",gross_salary);
printf("*******************************************************************\n");
printf("\nTotal OT hour\t\t: ");
scanf("%lf",&OT);
printf("OT Rate \t\t: RM %.2f\n",OT_rate);
total_OT_payment = OT * OT_rate;
printf("Total OT Payment \t: RM %.2lf\n",total_OT_payment);
printf("*******************************************************************\n");
net_salary = gross_salary + total_OT_payment;
printf("Net Salary\t\t: RM %.2lf",net_salary);
printf("\n*******************************************************************\n");
printf("Thank you , for using this program and have a nice day.\n");
printf("Do you want to continue?(y/n) : ");
scanf("%s",&a);
}
while (ex =='y' || ex == 'Y');
}
I'll be glad to here from ya'll. Thank you