else if statements

  • Thread starter Thread starter RHilfi
  • Start date Start date
R

RHilfi

Guest
Hi eveyone

Im just learning C# and are playing around with else if statements.
My question is (from the code below) why the else statement is not working? The user types in an age under 30 and the program outputs that they are older.



using System;

namespace ifelse_Statement
{
class Program
{
static void Main(string[] args)
{
string firstName, lastName, fullName, howFeel;
int age;


Console.WriteLine("Please enter your first name");
firstName = Console.ReadLine();

Console.WriteLine("Please enter your last name");
lastName = Console.ReadLine();

fullName = string.Concat(firstName, " ", lastName);

Console.WriteLine("Hello " + fullName + ", Are you feeling well today?");
howFeel = Console.ReadLine();

if (howFeel == "Yes" || howFeel == "yes" || howFeel == "YES")
{
Console.WriteLine("That is great " + fullName + ", I am too!");
}
else if (howFeel == "No" || howFeel == "no" || howFeel == "NO")
{
Console.WriteLine("Im sorry " + fullName + ", That is a shame!");
}
else
{
Console.WriteLine("Im sorry, Im not programmed to compute that response!");
}

Console.WriteLine("How old are you?");
age = Console.Read();
if (age > 30)
{
Console.WriteLine("WOW " + fullName + ", you are older than me!");
}
else
{
Console.Write("although you are younger than me " + firstName + ", you do not look it! hahahahaha");
}

}
}
}

Continue reading...
 
Back
Top