Getting A Raise | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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)); }

25th Feb 2021, 9:18 PM
Rafael F Pimentel
Rafael F Pimentel - avatar
3 Answers
+ 3
You should make use of Double type otherwise x/100 will always return 1 for 0.1,0.2 ,0.3 , ....
25th Feb 2021, 9:57 PM
Abhay
Abhay - avatar
+ 3
Thanks a lot guys
26th Feb 2021, 4:20 AM
Rafael F Pimentel
Rafael F Pimentel - avatar
+ 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
25th Feb 2021, 9:58 PM
Mhd AlHaj Houssein
Mhd AlHaj Houssein - avatar