- 1

Why if doesn’t work?

In my code , if ( x<1000) doesn’t work using System; using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; namespace SoloLearn { class Program { static void Main(string[] args) { int totalPrice = Convert.ToInt32(Console.ReadLine()); //call the method Console.WriteLine(Discount(totalPrice)); } //complete the method declaration static double Discount(int x) { //complete the method body double price; if(x < 1000) { price = Convert.ToDouble(x); } else { price = Convert.ToDouble(x-x*0.2); } return price; } } }

1st Jan 2021, 11:39 PM
Zhilin Hu
6 Answers
+ 2
Zhilin Hu for 800 it gave me output as 800 only
2nd Jan 2021, 12:00 AM
Abhay
Abhay - avatar
+ 1
For input 50 I get output 50 and for 1100 I get 880 ,works fine I guess?
1st Jan 2021, 11:43 PM
Abhay
Abhay - avatar
+ 1
No problem!
2nd Jan 2021, 12:03 AM
Abhay
Abhay - avatar
+ 1
i found my oroblem. it should be 10000 , not 1000.
2nd Jan 2021, 12:32 AM
Zhilin Hu
0
in the program designed input 800 , my ouput is 640, it should be 800. no matter how to switch the consition, it always correct for the input >= 1000
1st Jan 2021, 11:56 PM
Zhilin Hu
0
it is strange. i didn’t see any error in the code either. but couldn’t go through. it why i lost. thank you , Abhay
2nd Jan 2021, 12:02 AM
Zhilin Hu