It seems I’m not breaking any rules because it seems to run just fine but I get the feeling I’m doing it wrong.

Question: Write code to repeatedly prompt the user for a number and sum it. When the sum exceeds 100, stop prompting and display the sum. You must not display the sum until the end. You must use a do loop.

 { int end = 100; string intputstring; int input; double sum = 0; do { { Console.WriteLine("Enter a number to sum: "); intputstring = Console.ReadLine(); input = Convert.ToInt32(intputstring); sum = input + sum; if (input > end || sum > end) { Console.WriteLine("total sum is {0}", sum); } } } while (sum < end ); Console.ReadKey(); 

submitted by /u/ilikecooter
[link] [comments]

Leave a Reply