0
Getting A Raise
My code doesn't gimme the right output. Could someone help me out? The output doesn't return the increased salary. static void Main(string[] args) { int salaryBudget = Convert.ToInt32(Console.ReadLine()); int percent = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Before the increase: " + salaryBudget); //complete the method call Increase(ref salaryBudget, percent); Console.WriteLine("After the increase: " + salaryBudget); } //complete the method static void Increase(ref int y, int x) { y = y + (y * (x/100)); }
3 odpowiedzi
+ 3
You should make use of Double type otherwise x/100 will always return 1 for 0.1,0.2 ,0.3 , ....
+ 3
Thanks a lot guys
+ 2
You should change percent and salaryBudget variables to a data types like (double) or (float), also changing the parameters of the increase method to doubles, To know the reason of this let me take an example:
budget = 1000
percent = 50
y = 1000 + (1000 * (50/100))
---> the result of 50/100 here is 0 because c# automatically converts it to an integer type so y = 1000 + 0 = 1000
here is the corrected code:
https://code.sololearn.com/clk010mC46gV/?ref=app