Ex 30. In a certain city, police officers receive extra pay for weekend duties. Their hourly wage is increased by 50% for Saturday work and doubled for Sunday.
Write a program that requests the name of the officer, the hourly wage, and the number of hours worked each day, and return the weekly salary
Use a loop to request the hours worked each day.
(Hint use an array of size 7 to hold the hours worked each day, you may also use another array of 7 to hold the names of each day of the week (Sun, Sat, Mon, Tues, Wed, Thur, Fri)
static void Main(string[] args)
{
double [] hr = { 0, 0, 0, 0, 0, 0, 0 } ;
string [] day = { "sun", "mon", "tue", "wed", "thur", "fri", "sat" };
double weeklysalary = 0;
Console.Write("Enter your name: ");
string name = Console.ReadLine();
Console.Write("Enter your hourly wage: ");
double wage = double.Parse(Console.ReadLine());
for (int i = 0; i < hr.Length; i++)
{
Console.Write("Enter amount of hour on {0} you work: ", day[i]);
int wkhour = int.Parse(Console.ReadLine());
hr[i] = wkhour;
}
for (int i = 0; i < day.Length; i++)
{
if (day[i] == "sat")
{
weeklysalary += hr[i] * (wage * 1.5);
}
else if (day[i] == "sun")
{
weeklysalary += hr[i] * (wage * 2);
}
else
{
weeklysalary += hr[i] * wage;
}
}
Console.WriteLine("Office name: {0}", name);
Console.WriteLine("Weekly Salary is: {0:C}", weeklysalary);
Console.ReadLine();
}
}
}
No comments:
Post a Comment