0

Need solution for C# Problem.

The Problem: A store is running a promotion: if the total purchase price is equal to or exceeds 10000, the price will be discounted by 20%. The program you are given takes the total purchase price as input. Complete the given method to take the total purchase price as an argument, and calculate and return the discounted price if campaign's requirement is satisfied. The method should return the same price if discount is not given. Sample Input 13000 Sample Output 10400 Explanation 13000>10000, so the discount should be given: 13000-(0.2*13000) = 10400. Hint You need to use if else statements inside the method. My code: namespace SoloLearn { class Program { static int Discount(int x) { //complete the method body if (x >= 10000) { double totalPrice; totalPrice = (x * 0.2) - x; } else { Console.WriteLine(x); } } static void Main(string[] args) { int totalPrice = Convert.ToInt32(Console.ReadLine()); //call the method Discount(totalPrice); } } } error CS0161: 'Program.Discount(int)': not all code paths return a value How to fix?

24th Jul 2021, 8:44 PM
WeiZed
4 odpowiedzi
+ 1
Fixed. namespace SoloLearn { class Program { static double Discount(double money) { if (money >= 10000) { double x = money - (money * 0.2); return x; } else { return money; } } static void Main(string[] args) { int totalPrice = Convert.ToInt32(Console.ReadLine()); Discount(totalPrice); Console.WriteLine(Discount(totalPrice)); } } }
24th Jul 2021, 9:06 PM
WeiZed
0
WeiZed If your problem has been fixed then you could delete this thread because now doesn't make sense to be here.
25th Jul 2021, 6:00 AM
A͢J
A͢J - avatar
0
WeiZed, Just as a future reference, next time you post a question, it will be nice if you share a code bit link rather than raw text code. Here's how to share code bit link in case you didn't know or forget. https://www.sololearn.com/post/75089/?ref=app
25th Jul 2021, 6:55 AM
Ipang
0
Depending on the function you must return a variable of the type of the function you declare, unless it is null, these types of errors are what help you learn, it happens to all of us! 🧡
27th Jul 2021, 6:34 AM
Monica Martinez
Monica Martinez - avatar