Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace ConsoleTesting
- {
- class ConsoleTesting
- {
- static void Main()
- {
- List<int> nums = new List<int>();
- Console.WriteLine("Enter five valid integers:");
- for (int i = 0; i < 5; )
- {
- Console.Write((i + 1) + ". ");
- int temp;
- bool isInt = int.TryParse(Console.ReadLine(), out temp);
- if (isInt == false)
- {
- Console.WriteLine("Not a valid integer. Try again:");
- }
- else
- {
- nums.Add(temp);
- i++;
- }
- }
- Console.WriteLine("Sum: " + nums.Sum());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment