Conference badge
The registration desk at a small conference prints paper badges. Each badge shows the attendee's name in capital letters on the first line, the organisation they belong to on the second line, and underneath a rule made of = characters that is exactly as long as the longer of those two lines.
Read the name and the organisation and print the badge.
Input
Two lines: the attendee's name (1-40 characters, may contain spaces) and the organisation (1-40 characters, may contain spaces).
Output
Three lines: the name in upper case, the organisation exactly as given, and a line of = characters whose length equals the longer of the first two lines.
Example 1
Input
ada byron Engine Works
Output
ADA BYRON Engine Works ============
"Engine Works" has 12 characters, more than the 9 in "ADA BYRON", so the rule is 12 characters long.
Constraints
- Each line has between 1 and 40 characters
- Lines contain letters, digits and spaces only
Hints
Hint 1 of 3
name.ToUpper() returns a new string in capitals; it does not change name itself.
Hint 2 of 3
Every string has a Length property. Math.Max(a, b) picks the larger of two numbers.
Hint 3 of 3
new string('=', 12) builds a string of twelve = characters.
Solution
Show a reference solution and explanation
string name = Console.ReadLine()!;
string organisation = Console.ReadLine()!;
string upperName = name.ToUpper();
int width = Math.Max(upperName.Length, organisation.Length);
Console.WriteLine(upperName);
Console.WriteLine(organisation);
Console.WriteLine(new string('=', width));
Why it works
Strings in C# are immutable, so ToUpper() hands back a new string rather than editing the original; storing that result in a variable lets you both print it and measure it. The rule's width is the larger of the two lengths, which Math.Max gives directly, and the string(char, int) constructor repeats one character that many times. Note that upper-casing does not change the length, so measuring either name or upperName gives the same width.
Lesson for this exercise: C# Syntax and Your First Program