Skip to content

Instantly share code, notes, and snippets.

@Brianceasar
Created November 30, 2022 06:32
Show Gist options
  • Save Brianceasar/b6f897d9755d4666f7b31cfee435fdde to your computer and use it in GitHub Desktop.
Save Brianceasar/b6f897d9755d4666f7b31cfee435fdde to your computer and use it in GitHub Desktop.
program that reads five integer numbers and prints their sum. If an invalid number is entered the program should prompt the user to enter another number.
class program
{
static void Main(string[] args)
{
int a,b,c,d,e;
Console.Write("Enter first number: ");
bool isaInt = int.TryParse(Console.ReadLine(), out a);
Console.Write("Enter second number: ");
bool isbInt = int.TryParse(Console.ReadLine(), out b);
Console.Write("Enter third number: ");
bool iscInt = int.TryParse(Console.ReadLine(), out c);
Console.Write("Enter fourth number: ");
bool isdInt = int.TryParse(Console.ReadLine(), out d);
Console.Write("Enter fifth number: ");
bool iseInt = int.TryParse(Console.ReadLine(), out e);
if (isaInt & isbInt & iscInt & isdInt & iseInt)
{
Console.WriteLine("The sum of all five numbers = {0}", a+b+c+d+e);
}
else
{
Console.WriteLine("Enter valid integer numbers! ");
}
}
}
@Yqmqto
Copy link

Yqmqto commented Jan 21, 2024

nc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment