Hello everyone,
I'm a grown up man who's taking a part time course at a local University to gain more knowledge about programming. Since I'm in full job next to the course, I'm not able to attend the lectures, but I'm doing all the projects/tasks that we are obliged to do. I have never asked a programming question before, since if I wonder about something I can Google it or read it in my book. But now I've done all that, and I still have an error I can't get by.
I want to read in a value (integer or double) from a Console application. Then I want to make this value a Double, so that I can use it in my calculations. It's a simple task about calculating resistance in a electric circuit.
I have this code:
It gives me this error:
(It's the same error if I use Console.ReadLine() instead.
Then I try this code, and also get an error:
It gives me he same error:
I hope anyone of you could please help me with this error. All help would be very much appriceated! Thanks!
I'm a grown up man who's taking a part time course at a local University to gain more knowledge about programming. Since I'm in full job next to the course, I'm not able to attend the lectures, but I'm doing all the projects/tasks that we are obliged to do. I have never asked a programming question before, since if I wonder about something I can Google it or read it in my book. But now I've done all that, and I still have an error I can't get by.
I want to read in a value (integer or double) from a Console application. Then I want to make this value a Double, so that I can use it in my calculations. It's a simple task about calculating resistance in a electric circuit.
I have this code:
C#:
intMotstandsVerdi = Convert.ToInt32(Console.Read());
dblMotstandsVerdi = Convert.ToDouble(intMotstandsVerdi);
CS0266 Cannot implicitly convert type 'double' to 'int'. An explicit conversion exists (are you missing a cast?)
(It's the same error if I use Console.ReadLine() instead.
Then I try this code, and also get an error:
C#:
dblMotstandsVerdi = Double.Parse(Console.ReadLine());
I have googled and googled, but all the answers are that you have to Parse the input or convert the integer to Double. That's why I'm asking this question.CS0266 Cannot implicitly convert type 'double' to 'int'. An explicit conversion exists (are you missing a cast?)
I hope anyone of you could please help me with this error. All help would be very much appriceated! Thanks!
Last edited by a moderator: