CSCI 1301 – Lab 15

Clément Aubert

March 4, 2019

Flavors of while loops

An example of execution could be:

Enter a positive number to sum, or a negative number to exit
12
Enter a positive number to sum, or a negative number to exit
3
Enter a positive number to sum, or a negative number to exit
-2
Your total is 15.

Identify what type of loop it is: is it user-controlled, counter-controlled, or sentinel-controlled? Does it use a counter, a sentinel value, or an accumulator?

TryParse Method

Getting Familiar With It

Consider the code we just studied:

What happen if:

Using It

  1. Write a code that ask the user to enter an integer, and ask the user again as long as the user entered something that isn’t an integer.
  2. Actually, there is a TryParse method in other classes as well: there is for instance a Double.TryParse and a Decimal.TryParse method. Write a small program that uses one of them.