lundi 16 mars 2015

How to check for a double type response in an if statement

Language: C#


I'm trying to check if the user's response is a double or an int, but the int is specific, whereas the double is not, as I probably made a right mess of explaining it, here's the code:



Console.WriteLine("\n 2) Q: How old is Sally? \n");

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

double dSallyAge = Convert.ToDouble((nSallyAge));

if (nSallyAge == 62 || dSallyAge == 62.0)
{

// Increase Score

sUser1Score++;

Console.WriteLine("\n A: Correct, Sally's age is 62, you have been awarded 1 point. \n");

Console.ReadLine();

}


What I'm trying to do, is instead of dSallyAge HAS to equal 62.0, it just has to equal any double figure... Thanks :D


Aucun commentaire:

Enregistrer un commentaire