Programming 1 Week 3
Programming 1 Week 3
Week 3
Gerwin van Dijken ([email protected])
1
Program term 1.1 (Programming 1)
01 (wk 36) Introduction C# / Visual Studio 2022 (Community)
02 (wk 37) Sequence
03 (wk 38) Selection
04 (wk 39) Iteration
05 (wk 40) Arrays
06 (wk 41) Methods
07 (wk-42) no classes
08 (wk 43) Repetition / practice exam
09 (wk-44) exam (practical, computer)
10 (wk-45) -
‒ Empty functions (event handlers) inside code (windows forms) Remove them
‒ There are better ways to format strings then (ab)using the + operator
Console.Write(hours.ToString("00") + ":" + minutes.ToString("00") + ":" + seconds.ToString("00"));
It’s better to use:
Console.Write($"{hours:00}:{minutes:00}:{seconds:00}");
3 Programming 1 - Week 3 22/23
Common mistakes – Week 2 (2)
‒ Don’t perform mathematical operations while printing output!
Console.WriteLine($"VAT: {input * VatRate:0.00}”);
It’s better to use:
double vat = input * VatRate;
Console.WriteLine($"VAT: {vat:0.00}");
read seconds
hours = seconds / 3600
modulo
(remainder)
seconds = seconds % 3600
minutes = seconds / 60
seconds = seconds % 60
display hours, minutes, seconds
6 Programming 1 - Week 3 22/23
Selection types
Selection → a decision structure
if <condition>
<statement(s)>
A-side B-side
A-side B-side
23 Programming 1 - Week 3 22/23
Truth table: OR
A B A OR B
(A ˅ B)
0 0 0
0 1 1
1 0 1
1 1 1
A-side B-side
A-side B-side
25 Programming 1 - Week 3 22/23
Exercise 3 – medal table
Determine whether the Netherlands are positioned above Germany in the
medal table (Olympic Games). Ranking depends on the number of gold, silver
and bronze medals.
display NLHigher
display NLHigher