0

Im getting the error in the title in my code and dont know why. I just started my first class today so im quite lost. Have looked in my school books and cant find anything.

Here is the code:

        Console.WriteLine("Vad heter du i förnamn?");
        string förnamn = Console.ReadLine();
        Console.WriteLine("Vad heter du i efternamn?");
        string efternamn = Console.ReadLine();
        String namn = förnamn + " " + efternamn;
        Console.WriteLine("Hur gammal är du?");
        int ålder = Console.ReadLine();      <----- ERROR HERE
        int pension = ålder - 65;

Sorry if the text is in swedish aswell....

Thanks in advance!

Kian Parsa
  • 5
  • 1
  • 2
  • well, `ReadLine()` returns a `string`. A `string` is not a `int`, so if you want to interpret the `string` as an `int` you need to *parse* it... via any of the `int.Parse`, `int.TryParse` or `Convert.ToInt32` methods... – Marc Gravell Nov 27 '17 at 12:08
  • Console.Readline() reads information as a string (see https://msdn.microsoft.com/en-us/library/system.console.readline(v=vs.110).aspx ) You will need to cast this to a number (int), have a look here: https://stackoverflow.com/questions/1019793/how-can-i-convert-string-to-int or here: https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/types/how-to-convert-a-string-to-a-number for how to do that. Once you've got that done you might want to do error checking to make sure the value is actually a number and someone's not type plain text. Good luck! – d219 Nov 27 '17 at 12:11

0 Answers0