Help please (I dont get it) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Help please (I dont get it)

Hello, somehow the code below cant find the "Rechner" Method what im doing wrong? using System; using System.IO; using System.Xml; namespace hi { public class Rechnen { public static int Rechner(string num3, string num4) { bool success1 = int.TryParse(num3, out int endNumber1); bool success2 = int.TryParse(num4, out int endNumber2); if (success1) { if (success2) { try { int Ergebnis = endNumber1 / endNumber2; return Ergebnis; } catch (DivideByZeroException e) { Console.WriteLine(e.Message); return 0; } } else Console.WriteLine("num2 is false: {0}", num4); return 0; } else Console.WriteLine("num1 is false: {0}", num3); return 0; if (success2 == false) { Console.WriteLine("num2 is false: {0}", num4); return 0; } } } class Program { static void Main(string[] args) { try { Console.WriteLine("Enter a number: "); int num1 = int.Parse(Console.ReadLine()); Console.WriteLine("Enter another number: "); int num2 = int.Parse(Console.ReadLine()); Console.WriteLine(num1 / num2); } catch (DivideByZeroException e) { Console.WriteLine(e.Message); } catch (FormatException e) { Console.WriteLine(e.Message); } //the same agai

21st Feb 2020, 5:31 PM
Michael
4 Answers
+ 2
hey Michael you can put this on codeplayground and link it here so that it will be easy to get it fix for you
21st Feb 2020, 5:38 PM
✳AsterisK✳
✳AsterisK✳ - avatar
+ 1
here is the test of the code //the same again but in a other way Console.WriteLine("Enter a number: "); string num3 = Console.ReadLine(); Console.WriteLine("Enter another number: "); string num4 = Console.ReadLine(); Rechner geteilt = new Rechner(); int result = Rechner(num3, num4); Console.WriteLine(result); } } }
21st Feb 2020, 5:32 PM
Michael
21st Feb 2020, 8:07 PM
Michael
0
Thank you for putting the code in the playground. There are two ways to solve this problem, if you mix them it is go an be a mess. First Rechner is part of the class Rechnen. So to reach Rechner you need to use the full name Rechnen.Rechner. Option 1) Rechner is a static method. So you do not need a object to do the equation. Rechner geteilt = new Rechner(); //remove this line int result = Rechnen.Rechner(num3, num4); //add Rechnen to this line Option 2) Make Rechner a non-static method public int Rechner(string num3, string num4) Create a object of type Rechnen Rechnen geteilt = new Rechnen(); Use the created object to call the Rechner method int result = geteilt.Rechner(num3, num4);
21st Feb 2020, 9:12 PM
sneeze
sneeze - avatar