0

Why does my code output incorrectly for a specific input? (C#)

My code will be below. When the input is 7, the code outputs "Profit", when "Broke Even" is expected, but according to my calculations, profit should be correct? int buildPrice = 2000000; int sellPrice = 3000000; int insurance = 1000000; int expenses = Convert.ToInt32((buildPrice * 10) + insurance); int sales = Convert.ToInt32(Console.ReadLine()); int gross = Convert.ToInt32(sellPrice * sales + insurance); /*Console.WriteLine(gross); Console.WriteLine(expenses);*/ if (gross > expenses){ Console.WriteLine("Profit"); } else if (gross < expenses){ Console.WriteLine("Loss"); } else{ Console.WriteLine("Broke Even"); }

24th Jul 2021, 6:47 AM
Evelyn
Evelyn - avatar
1 Answer
0
It's not necessary to add insurance for gross. int gross = Convert.ToInt32(sellPrice * sales);
24th Jul 2021, 12:14 PM
Simba
Simba - avatar