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!!!

Recommended Answers

All 3 Replies

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

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);

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);
		}
	}
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.