+ 1

How to solve "Buy more, get more" If statement - C #?

I need help with this problem, which says the following: The if Statement A restaurant provides a 15% discount if the bill exceeds 1500․ Write a program to take the bill total as input and output the discount amount. Sample Input 2700 Sample Output 405 Hint 405 is the discount for a 2700 bill (0.15*2700). My code is as follows: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { class Program { static void Main(string[] args) { //tomando la cuenta como entrada int bill = Convert.ToInt32(Console.ReadLine()); //tu código va aquí int acount = 2700; if(bill > 1500) { Console.WriteLine(0.15 * acount); } } } }

24th Jun 2021, 3:59 PM
Alex Narváez
Alex Narváez - avatar
2 ответов
+ 3
Why did you predefine the amount and change the amount? No need to change the amount and define amount. You have to change the value of the bill, not the amount. Write this: if(bill > 1500) { Console.WriteLine(0.15 * bill); } Here is the sample code: https://code.sololearn.com/c9A25A1205a1
24th Jun 2021, 4:04 PM
The future is now thanks to science
The future is now thanks to science - avatar
0
Thank you very much for your help, it helped me a lot and I will keep it in mind for the next time. I defined the value of the account because the description said that the input should be 2700, however I see that it is not always necessary to put input values. Thank you very much colleague
24th Jun 2021, 4:10 PM
Alex Narváez
Alex Narváez - avatar