Click here to Skip to main content
14,934,114 members
Please Sign up or sign in to vote.
1.00/5 (5 votes)
See more:
The manager performs the following tasks:
1- Adding a new employee;
2- Approving the employee's payments for lunch meals and regular invoices, provided that it does not exceed the amount of each
Including 5000 liras per day. A schedule of invoices is sent
On the twentieth of each month to the principal for the past 30 days;
3 - Calculation of the average daily payments for each employee;
4- Calculating the monthly amount that must be paid to each employee, as the monthly salary is combined with the daily average
For payments multiplied by the number of days of the month;
5- Calculating the annual performance bonus for employees, as there are two types of employees, permanent and contracted. Done
Classifying all employees into three categories (A), (B) and (C.) Administrative personnel are placed in Category (A) while
Non-management employees are placed in category (b) or category (c).
Employees with less than nine months of service are not eligible for the award. The amount of the reward is determined
For employees who qualify for the bonus according to the number of points they have obtained, the points value ranges between 1
And 100, as follows:
Points
Number of monthly salaries (bonus)
> = 80---------------------------------------------------

--------------------- 2
65-79
------------------ 1.0
50-64
------------------ 1
<50
------------------------ 5
6- View a list of all employees, their numbers and names;
7- View a list of all employees, their numbers, and the daily average of payments for each of them during one of the months.

Write a C Sharp language program

What I have tried:

<pre lang="C#">using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication4
{
    class Program
    {
        static void Main(string[] args)
        {
            int x;
            Console.WriteLine("1 : employer");
            Console.WriteLine("2 : employee");
            Console.WriteLine("3 : exit");
            
           x=int.Parse(Console.ReadLine());

           if (x == 1)
           {
               Console.WriteLine("you are employer");
             
               string username, password;
               int ctr = 0;
               Console.Write("\n\nCheck username and password :\n");
               Console.Write("N.B. : Default user name and password is :abcd and 1234\n");
               Console.Write("------------------------------------------------------\n");

               do
               {
                   Console.Write("Input a username: ");
                   username = Console.ReadLine();

                   Console.Write("Input a password: ");
                   password = Console.ReadLine();

                   if (username != "abcd" || password != "1234")
                       ctr++;
                   else
                       ctr = 1;

               }
               while ((username != "abcd" || password != "1234") && (ctr != 3));

               if (ctr == 3)
                   Console.Write("\nLogin attemp three or more times. Try later!\n\n");
               else
                   Console.Write("\nThe password entered successfully!\n\n");

               // Type your Employee Name and press enter
               Console.WriteLine("Employee Name:");

               // Create a string variable and get user input from the keyboard and store it in the variable
               string EmployeeName = Console.ReadLine();

               // Print the value of the variable (userName), which will display the input value
               Console.WriteLine("Employee Name is: " + EmployeeName);



               
           }
           if (x == 2)
           {
               Console.WriteLine("you are employee");
               string username, password;
               int ctr = 0;
               Console.Write("\n\nCheck username and password :\n");
               Console.Write("N.B. : Default user name and password is :abcd and 1234\n");
               Console.Write("------------------------------------------------------\n");

               do
               {
                   Console.Write("Input a username: ");
                   username = Console.ReadLine();

                   Console.Write("Input a password: ");
                   password = Console.ReadLine();

                   if (username != "a12345678" || password != "1234")
                       ctr++;
                   else
                       ctr = 1;

               }
               while ((username != "a12345678" || password != "1234") && (ctr != 3));

               if (ctr == 3)
                   Console.Write("\nLogin attemp three or more times. Try later!\n\n");
               else
                   Console.Write("\nThe password entered successfully!\n\n");



           }
           if (x == 3)
           {
               Console.WriteLine("good bye");
               
           }

            
        }
    }
}
Posted
Updated 5-May-21 20:06pm
v3
Comments
Richard MacCutchan 5-May-21 17:07pm
   
What is the question?
Malek Alshorbaji 5-May-21 18:04pm
   
I want to solve the code c#
BillWoodruff 6-May-21 1:02am
   
You need to ask specific questions based on specific parts of your code, with clear descriptions of what works and what does not work, including specific error messages and where they occur.

1 solution

Start by changing the whole way you write code: refactor your code into separate methods.
For example, your code decides if the user is an employer or an employee, and then act differently. Split that into separate methods: EmployerActivities and EmployeeActivities
This makes the Main function shorter and easier to read:
static void Main(string[] args)
{
   Console.WriteLine("1 : employer");
   Console.WriteLine("2 : employee");
   Console.WriteLine("3 : exit");
   int operation = int.Parse(Console.ReadLine());

   if (operation == 1)
   {
       EmployerActivities();
   }
   else if (operation == 2)
   {
       EmployeeActivities();
   }
   else if (operation == 3)
   {
       Console.WriteLine("good bye");
   }
}
And that makes it more obvious that it's already wrong:
1) What happens if the user enters "4" or "5"?
2) Shouldn't it loop round to allow another user?

Then, in both the Employer and Employee code you do the same things: login (which I have to say is very, very badly designed - you give them the damn passwords!) So move login code to a new method, pass it a list of valid logins (for employer and employee as appropriate) and call that from both new methods. Again, your code becomes easier to read, and more reliable as well.

If you are far enough into your course, I'd suggest creating two classes: Employee, and Employer (which derives from Employee) to separate the functions even further.

But ... the really big problem here is that your code doesn't match the question in any way, shape, or form: it's possible that there is a big chunk of question missing but we don't know that.

Then start working on the actual question: take it one bit at a time, and work your way through it. This may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]
   
Comments
CPallini 6-May-21 3:10am
   
5.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900