0

hi,hello to anyone there can anyone help me to fix my problem about C#.Net conditional exercise.The problem is write a problem that asks the user for the hours worked for the week and hourly rate.The basic salary is computed as: Salary=hours worked*hourly rate
bonus are given:
No.of hours>45 Bonus of 500
No. of hours>40and<=45 Bonus of 250
No.of hours>35and<=40 Bonus of 150
display the basic salary,bonus,and total salary
the sample output:
Hours worked:10
Hourly rate:10
Basic salary:100
Bonus:0
Total salary:100
what should i do,the bonus & hours worked are a double data type and other are a decimal data type.Please help me to fix this problem SOP.Thanks!!!

4
Contributors
3
Replies
7
Views
9 Years
Discussion Span
Last Post by david.crawford
0

Show us your effort to help you, friend! your question is straightforward!
You just need to read about if else in C#.

0

Not sure what you are asking but I suspect you might be asking about rounding/converting issues.

If you are having a problem with the # of decimals try the following:
double dAmount = Math.Round(Amount,2,MidpointRounding.AwayFromZero);

0

Here, but do your own homework next time.

using System;

namespace BonusHours
{
	class MainClass
	{
		public static void Main(string[] args)
		{
			string hours;
			string rate;
			double hoursAsNum;
			double rateAsNum;
			double salaryAsNum;
			double bonusAsNum;
			double totalSalaryAsNum;
			Console.WriteLine("Number of Hours");
			hours = Console.ReadLine();
			Console.WriteLine("Hourly Rate");
			rate = Console.ReadLine();
			hoursAsNum = double.Parse(hours);
			rateAsNum = double.Parse(rate);
			if(hoursAsNum > 45)
				bonusAsNum = 500;
			else if(hoursAsNum > 40 && hoursAsNum <= 45)
				bonusAsNum = 250;
			else if(hoursAsNum > 35 && hoursAsNum <=40)
				bonusAsNum = 250;
			else
				bonusAsNum = 0;
			salaryAsNum = hoursAsNum * rateAsNum;
			totalSalaryAsNum = salaryAsNum + bonusAsNum;
			
			Console.WriteLine("Hours worked: " + hoursAsNum);
			Console.WriteLine("Hourly rate: " + rateAsNum);
			Console.WriteLine("Basic salary: " + salaryAsNum);
			Console.WriteLine("Bonus: " + bonusAsNum);
			Console.WriteLine("Total salary: " + totalSalaryAsNum);
		}
	}
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.