Can someone look at the below code and explain to me what is wrong. I have ran the problems set input and expected output on my machine and it returns exactly how it should. I even account for strings and numbers larger than two digits.
Thanks!
using System;
using System.Collections.Generic;
namespace RefreshingSkills
{
public static class Program
{
// Method To Check String Value For Contains Integer
public static bool IsInteger(this string s)
{
if (String.IsNullOrEmpty(s))
{
return false;
}
int i;
return Int32.TryParse(s, out i);
}
private static void Main(string[] args)
{
// Prevents Non Zero Exit Code Error
try
{
// Stores The Value Of User Input
List<int> number = new List<int>();
string userInput;
Console.WriteLine("Enter Numbers:");
// Loop To Allow User Input Of Numbers
do
{
userInput = Console.ReadLine();
if ((userInput.Length > 2 || !IsInteger(userInput)) && userInput.Length != 0)
{
Console.WriteLine("Enter a two digit number.");
}
else if (userInput.Length != 0 && IsInteger(userInput))
{
number.Add(Convert.ToInt32(userInput));
}
} while (userInput.Length != 0);
Console.WriteLine();
Console.WriteLine("Output:");
// Loop To Output Numbers To The Console
foreach (var item in number)
{
if (item != 42)
Console.WriteLine(item);
else
break;
}
// Hold Console App
Console.ReadLine();
}
catch (Exception e)
{
return;
}
}
}
}
created
last reply
- 1
reply
- 842
views
- 2
users