exercise 1 introduction to c# cis-2320. 2 code the c# program to prompt the user to key in 12...

4
Exercise 1 Exercise 1 Introduction to C# Introduction to C# CIS-2320 CIS-2320

Upload: katrina-murphy

Post on 18-Jan-2016

224 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Exercise 1 Introduction to C# CIS-2320. 2 Code the C# program to prompt the user to key in 12 integer values from the keyboard. If a value containing

Exercise 1Exercise 1

Introduction to C#Introduction to C#

CIS-2320CIS-2320

Page 2: Exercise 1 Introduction to C# CIS-2320. 2 Code the C# program to prompt the user to key in 12 integer values from the keyboard. If a value containing

2

Code the C# program to prompt the user to key in 12 integer values from the keyboard.

• If a value containing invalid characters is detected, display an error message, and skip the value.

• If a negative value is detected, display an error message, and skip the value.

• If a value greater than 3 digits (999) is detected, display an error message, and skip the value.

• When 12 valid values have been entered: Display the sum of the values entered Display the largest and smallest value entered Display the average of the values entered to

the nearest 2 decimal places

Page 3: Exercise 1 Introduction to C# CIS-2320. 2 Code the C# program to prompt the user to key in 12 integer values from the keyboard. If a value containing

3

Sample program output:

Enter a 1 to 3 digit number: 345 Enter a 1 to 3 digit number: 55 Enter a 1 to 3 digit number: 999 Enter a 1 to 3 digit number: -44 Error: Value entered is negativeEnter a 1 to 3 digit number: 674323 Error: Value entered is greater than 999Enter a 1 to 3 digit number: 1 Enter a 1 to 3 digit number: abc Error: Data entered contains invalid charactersEnter a 1 to 3 digit number: 4 Enter a 1 to 3 digit number: 77Enter a 1 to 3 digit number: 444 Enter a 1 to 3 digit number: -5 Error: Value entered is negativeEnter a 1 to 3 digit number: 789Enter a 1 to 3 digit number: 34 Enter a 1 to 3 digit number: 500 Enter a 1 to 3 digit number: 22 Enter a 1 to 3 digit number: 56 Sum of all values.....: 3326Largest value is......: 999Smallest value is.....: 1Average of the values.: 277.17

Page 4: Exercise 1 Introduction to C# CIS-2320. 2 Code the C# program to prompt the user to key in 12 integer values from the keyboard. If a value containing

4

Extra Points:

2 points: Create a class with all processing code in the constructor, then create an instance of this class in Main() calling it's constructor. Also create a DisplayTotals() method to display the total lines. Call this method from Main(). This class should be in a separate .cs file.Main() should look as follows: static void Main()

{ xxxxx ob = new xxxxx();

ob.DisplayTotals(); }

2 points: Display all error messages using the MessageBox class.