Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create an application in C# that lets the user enter a string containing series

ID: 3666104 • Letter: C

Question

Create an application in C# that lets the user enter a string containing series of numbers separated by commas. Here is an example of valid input: 7,9,10,2,18,6 The program should calculate and display the sum of all the numbers.

Thanks for your time!

Explanation / Answer

using System; class Class1 { public static void Main(string[] args) { Console.WriteLine("Input a series of numbers separated by commas:"); string input = Console.ReadLine(); char[] cDividers = { ',', ' ' }; string[] segments = input.Split(cDividers); int nSum = 0; foreach (string s in segments) { if (s.Length > 0) { if (IsAllDigits(s)) { int num = Int32.Parse(s); Console.WriteLine("Next number = {0}", num); nSum += num; } } } Console.WriteLine("Sum = {0}", nSum); } public static bool IsAllDigits(string sRaw) { string s = sRaw.Trim(); if (s.Length == 0) { return false; } for (int index = 0; index
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote