FAQ: Data Types and Variables - Converting Data Types

We are now more than one year passed the original notification about how confusing this lesson is. Yet this error is still not repaired. I just tried it, and I got the same message as the other users.
Are we not paying enough each month to at least have the decency to fix this?

At the end after running “int faveNumber = Convert.ToInt32(Console.ReadLine());” on the last excercise I get a green checkmark. My question is after running it again am I suppose to get an error? Or is that part of the excercise?

Are you getting the error at the end of the excercise as well?

Ok. This exercise should really be broken into three exercises and explained a little more since it is so early in the course.

First, I was confused because the exercise states that we are converting a string into an integer. Well, that doesn’t mean you type your answer to the question “What is your favorite number” as a string, for example “Nine”.

We are really learning (and it would help to explain it better) that when a user enters anything into your prompt it is treated as a string. So typing “9” as the answer turns “9” into a string.

Our actual challenge in this exercise is to convert “9” the string into 9 the integer. Maybe that was clear to everyone, but I come from different coding and this took a minute to figure out.

Now the exercise gets complicated, if you follow the instructions it will fail about twice. You are learning what doesn’t work, that is the purpose of the exercise up to this point. It is supposed to fail. So you learn what doesn’t work.

Then you are given guidance to use a Convert.ToX() method. In this case Convert.ToInt32().

So, for the grand finale, you are supposed to use:

int faveNumber = Convert.ToInt32(Console.ReadLine());

Then once you run… ta da … nothing happens.

That is the outcome you want. No errors. Congratulations.

Another person posted a better finish to this by adding:

Console.Write(“Is “);
Console.Write(faveNumber);
Console.Write(” your favorite number?”);

This gives you something to see after the conversion is successful.

It’s not a bad exercise, it’s just abstract in how it is presented. It really helped me understand what they mean by an explicit conversion, so it accomplished that task.

Hey There, I’m confused with what the initial data type for faveNumber is supposed to be. Is it a string or an int? because either way the input from the user will be a string anyway, which then gets converted to an int.