Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include <conio.h>
- //Salary function to calculate Employee's Salary
- void Salary(int s)
- {
- if(s<40) //Checks if the number of hours is less than 40 hours
- {
- printf("There is no Salary!\n"); //Print that there's no salary
- }
- else if((s>=40)&&(s<50)) //Checks if the number of hours ranges between 40 & 50 hours
- {
- s*=50; //Calculates his salary by multiplying the number of hours by 50 (s=s*50)
- printf("Your salary is %d\n",s); //Prints the salary after calculating it
- }
- else if((s>=50)&&(s<60)) //Checking if the number of hours ranges between 50 & 60
- {
- s*=60; //Calculates the salary by multiplying the number of hours by 60 for each hour (s=s*60)
- printf("Your salary is %d\n",s); //Prints the salary after calculating it
- }
- else if(s>=60) //Checks if the number of hours is greater thanm 60 (100 L.E per hour)
- {
- s*=100; //Calculates the salary by multiplying the number of hours by 100 for each hour (s=s*100)
- printf("Your salary is %d\n",s); //Prints the salary after calculating it
- }
- }
- //Password function used to check if the password is the correct one for each user or not
- int Password(char name,int defaultpw,int recpw) //Function declaration where name is the employee name, defaultpw is the default password for each employee, recpw is the received password entered by the user while logging in
- {
- if(defaultpw==recpw) //Checking if the entered password is the same as the default employee password
- {
- printf("The password is correct! Welcome %c\n",name); //Prints that the password is correct
- return 1; //return 1 to the main function
- }else
- {
- printf("Try again! Please enter the password:\n"); //When the password is not correct, it gives another chance
- scanf("%d",&recpw); //Scanf to recieve the password for the second time
- if(defaultpw==recpw) //checks if the entered password is correct or not
- {
- printf("The password is correct! Welcome %c\n",name); //If it's correct it prints that "The password is correct"
- return 1; //It also returns 1 to the main function
- }else
- {
- printf("Try again! Please enter the password:\n"); //If the password is incorrect for the second time, it gives him one last chance
- scanf("%d",&recpw); //Accepts the password for the third/last time from the user
- if(defaultpw==recpw) //Checks if the entered password is correct or not
- {
- printf("The password is correct! Welcome %c\n",name); //Prints that the password is correct incase it's correct
- return 1; //Returns 1 to the main function
- }else
- {
- printf("Wrong Entry!"); //Prints Wrong entry if the password is wrong for the last chance
- return 0; //return 0 to the main function
- }
- }
- }
- }
- void main(void)
- {
- int pw1,pw2,pw3,NewPw1=0,NewPw2=0,NewPw3=0,pass,ret,choice,hrs; //declaring variables where pw1 and NewPw1 belongs to employee a and so on
- char Employee; //used to check the employee's name
- printf("Please enter your username: \n"); //asking the user to enter the username
- Employee=getch(); //receiving the username using getch(); function
- printf("Please enter your password: \n"); //Asking the user to enter his password
- scanf("%d",&pass); //saving the password in the variable pass
- if(Employee=='A') //checking if the empployee is A
- {
- pw1=352; //setting his default password as 352
- if(NewPw1==0) //checking if the password is changed (If it's changed then it won't be equal to 0) so having it =0 means it didn't change
- {
- ret=Password(Employee,pw1,pass); //calling Password function to check if the password entered is correct for employee A or not and get a return if the password is correct the the return will be 1 while if it's wrong then it'll be 0
- }else
- {
- ret=Password(Employee,NewPw1,pass); //calling password function to check if the password entered is equal to the new password and get a return
- }
- }else if(Employee=='B') //Checking if the employee is B
- {
- pw2=245; //Setting his default password as 254
- if(NewPw2==0) //checking if the password is changed (If it's changed then it won't be equal to 0) so having it =0 means it didn't change
- {
- ret=Password(Employee,pw2,pass); //calling Password function to check if the password entered is correct for employee B or not and get a return if the password is correct the the return will be 1 while if it's wrong then it'll be 0
- }else
- {
- ret=Password(Employee,NewPw2,pass); //calling password function to check if the password entered is equal to the new password and get a return
- }
- }else if(Employee=='C') //Checking if the employee is C
- {
- pw3=367; //Setting his default password as 367
- if(NewPw3==0) //checking if the password is changed (If it's changed then it won't be equal to 0) so having it =0 means it didn't change
- {
- ret=Password(Employee,pw3,pass); //calling Password function to check if the password entered is correct for employee C or not and get a return if the password is correct the the return will be 1 while if it's wrong then it'll be 0
- }else
- {
- ret=Password(Employee,NewPw3,pass); //calling password function to check if the password entered is equal to the new password and get a return
- }
- }else
- {
- printf("Wrong Username!\n"); //Print "Wrong username" message if the entered username is wrong
- }
- if(ret==1) //It is used to check if the return from the Password function is "1" it means that the password is correct so it displays the menu
- {
- printf("1-Calculate your salary \n 2-Change your password\n"); //Displays the menu
- scanf("%d",&choice); //accept the user's choice from the menu
- if(choice==1) //If the user chose number one from menu, it will check the salary
- {
- printf("Please enter the number of hours: \n"); //Asking the user to enter the amount of hours
- scanf("%d",&hrs); //Accept the number of hours from the employee
- Salary(hrs); //Calling salary function and passing the number of hours to it so it calculate the salary.
- }else if(choice==2) //If the user chose number 2 from the menu, it will change his password
- {
- printf("Please enter your new password: \n"); //Asking the user to enter the new password
- if(Employee=='A') //checking if the user is Employee A
- {
- scanf("%d",&NewPw1); //Updating the NewPw1 variable with the new value
- printf("Dear A, You have changed your password succesfully!\n\n"); //Print msg saying that password changed successfully
- }else if(Employee=='B') //checking if the user is Employee B
- {
- scanf("%d",&NewPw2); //Updating the NewPw2 variable with the new value
- printf("Dear B, You have changed your password succesfully!\n\n"); //Print msg saying that password changed successfully
- }else if(Employee=='C') //checking if the user is Employee C
- {
- scanf("%d",&NewPw3); //Updating the NewPw3 variable with the new value
- printf("Dear C, You have changed your password succesfully!\n\n"); //Print msg saying that password changed successfully
- }
- }
- printf("Please enter your username: \n"); //Asking the user to enter his username
- Employee=getch(); //Receiving the username and saving it in a variable
- printf("Please enter your password: \n"); //asking the user to enter his password
- scanf("%d",&pass); //recieving his password and saving it in a variable
- //Repeating the same checking once again to check if the password is changed or not then pass the right password with the user name and the entered password to the password function to check if the entered password for the username is correct or not.
- if(Employee=='A') //Checking if the user is Employee A
- {
- pw1=352; //Setting his default password
- if(NewPw1==0) //Checking if the password is changed or not
- {
- ret=Password(Employee,pw1,pass); //Calling the password function
- }else
- {
- ret=Password(Employee,NewPw1,pass); //Calling the password function
- }
- }else if(Employee=='B') //Checking if the user is employee B
- {
- pw2==245; //Setting his default password
- if(NewPw2==0) //Checking if the password is changed or not
- {
- ret=Password(Employee,pw2,pass); //Calling the password function
- }else
- {
- ret=Password(Employee,NewPw2,pass); //calling the password function
- }
- }else if(Employee=='C') //Checking if the user is employee C
- {
- pw3=367; //Setting his default password
- if(NewPw3==0) //checking if the password is correct or not
- {
- ret=Password(Employee,pw3,pass); //calling the password function
- }else
- {
- ret=Password(Employee,NewPw3,pass); //calling the password function
- }
- }else
- {
- printf("Wrong Username!\n"); //Printing Wrong Username message
- }
- if(ret==1) //It is used to check if the return from the Password function is "1" it means that the password is correct so it displays the menu
- {
- printf("1-Calculate your salary\n2-Change your password\n"); //Displaing the menu for the user
- scanf("%d",&choice); //Accepting choice
- if(choice==1) //checking choice if it's 1
- {
- printf("Please enter the number of hours: \n"); //asking him to enter the amount of hours
- scanf("%d",&hrs); //Saving the number of hours
- Salary(hrs); //Calling salary function to calculate the employee's salary
- }else if(choice==2) //checking if choice is 2 from the menu so user can change his password
- {
- printf("Please enter your new password: \n"); //asking the user to enter his new password
- if(Employee=='A') //checking if the user is A Employee
- {
- scanf("%d",&NewPw1); //recieve the password and save it in the NewPw1
- printf("Dear A, You have changed your password succesfully!\n"); //Print message that the password has changed
- }else if(Employee=='B') //Checking if the user is employee B
- {
- scanf("%d",&NewPw2); //receive the password and save it in NewPw2
- printf("Dear B, You have changed your password succesfully!\n"); //Print message that the password has changed
- }else if(Employee=='C') //checking if the user is B employee is C
- {
- scanf("%d",&NewPw3); //recieve the password and save it in NewPw3
- printf("Dear C, You have changed your password succesfully!\n"); //Print message that the password has changed
- }
- }
- //Repeating the same thing again for the 3rd and last time which ask the user to enter his username and password then display the menu and so on.
- printf("Please enter your username: \n");
- Employee=getch();
- printf("Please enter your password: \n");
- scanf("%d",&pass);
- if(Employee=='A')
- {
- pw1=352;
- if(NewPw1==0)
- {
- ret=Password(Employee,pw1,pass);
- }else
- {
- ret=Password(Employee,NewPw1,pass);
- }
- }else if(Employee=='B')
- {
- pw2==245;
- if(NewPw2==0)
- {
- ret=Password(Employee,pw2,pass);
- }else
- {
- ret=Password(Employee,NewPw2,pass);
- }
- }else if(Employee=='C')
- {
- pw3=367;
- if(NewPw3==0)
- {
- ret=Password(Employee,pw3,pass);
- }else
- {
- ret=Password(Employee,NewPw3,pass);
- }
- }else
- {
- printf("Wrong Username!\n");
- }
- if(ret==1)
- {
- printf("1-Calculate your salary\n2-Change your password\n");
- scanf("%d",&choice);
- if(choice==1)
- {
- printf("Please enter the number of hours: \n");
- scanf("%d",&hrs);
- Salary(hrs);
- }else if(choice==2)
- {
- printf("Please enter your new password: \n");
- if(Employee=='A')
- {
- scanf("%d",&NewPw1);
- printf("Dear A, You have changed your password succesfully!\n");
- }else if(Employee=='B')
- {
- scanf("%d",&NewPw2);
- printf("Dear B, You have changed your password succesfully!\n");
- }else if(Employee=='C')
- {
- scanf("%d",&NewPw3);
- printf("Dear C, You have changed your password succesfully!\n");
- }
- }
- }else
- {
- printf("Try again later!\n"); //If he failed to enter the correct password for 3 times he gets error messsage and program stop
- }
- }else
- {
- printf("Try again later!\n"); //If he failed to enter the correct answer for 3 times he gets error message and program stop
- }
- }else
- {
- printf("Try again later!\n"); //If he failed to enter the correct password he gets error message and program stop
- } //If he failed to enter the correct password he gets error message and program stop
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement