Created
November 30, 2022 06:32
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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! "); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nc