im learning and i want to make so that if the age entered is 15 it will make a special message i just started yesterday so im trying to do random things to be sure i understand but i didnt learn that yet
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Meme
{
class Program
{
static void Main(string[] args)
{
string yourName;
Console.WriteLine("What is your name?");
yourName = Console.ReadLine();
Console.WriteLine("Hello {0}", yourName);
Console.WriteLine("What is your age?");
int yourAge = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Hello {0}, you are {1} years old", yourName, yourAge);
Console.WriteLine("What is your rank?");
int yourRank;
yourRank = Convert.ToInt32(Console.ReadLine());
const int Y = 15;
if ((yourAge = Y))
{
Console.WriteLine("NO");
}
}
}
}
==
not=
yourAge = Y
is your problem, think about what operator belongs here if you are trying to compare somethingif (yourAge == Y)
int.TryParse
to convert user-supplied strings to integers, because that way you have an opportunity to inform the user if they type something that cannot be converted to integer. This will then give you an opportunity to learn about loops!$
before the literal then you can do this:$"Hello {yourName} you are {yourAge} years old"
, which is somewhat easier to read.