svetlozar_kirkov

Five Integers Check if Int (Exercise)

Sep 28th, 2014
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.83 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace ConsoleTesting
  6. {
  7.     class ConsoleTesting
  8.     {
  9.         static void Main()
  10.         {
  11.             List<int> nums = new List<int>();
  12.             Console.WriteLine("Enter five valid integers:");
  13.             for (int i = 0; i < 5; )
  14.             {
  15.                 Console.Write((i + 1) + ". ");
  16.                 int temp;
  17.                 bool isInt = int.TryParse(Console.ReadLine(), out temp);
  18.                 if (isInt == false)
  19.                 {
  20.                     Console.WriteLine("Not a valid integer. Try again:");
  21.                 }
  22.                 else
  23.                 {
  24.                     nums.Add(temp);
  25.                     i++;
  26.                 }
  27.             }
  28.             Console.WriteLine("Sum: " + nums.Sum());
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment