CPPForSchool.com: Variable, Operator & Expression Set 2: Assignment 2
2.
Write a program which input three numbers and display the largest number using ternary operator.
It appears that my frustrations with ternary/conditional operators are becoming more justified. For this assignment, I was kind of at a loss. Based on my current comprehension of ternary operators, it is merely shorthand of if/else statements. With that said, I was still very confused on how to go about coding this assignment. In efforts to move forward, I had to refer to the sample solution from CPPforSchool.
In order to keep things fair, I took a screen capture of the solution provided by CPPforSchool. See below.
With that said, I quickly created a similar project that virtually mimicked the source. I changed the variable names from a, b, c, greatest to x, y, z, bignum. It appears that I simply need to practice more in order to have a stronger understanding of ternary operators. The code is more compact, but quite difficult to read, especially from a novice perspective. After a few YouTube videos, it became quite apparent that I was not the only one who felt this struggle with ternary operators. It makes sense. Reading if/else statements are far easier to comprehend at a glance over the use of question marks and colons to separate conditions and executable code.
It appears that my frustrations with ternary/conditional operators are becoming more justified. For this assignment, I was kind of at a loss. Based on my current comprehension of ternary operators, it is merely shorthand of if/else statements. With that said, I was still very confused on how to go about coding this assignment. In efforts to move forward, I had to refer to the sample solution from CPPforSchool.
In order to keep things fair, I took a screen capture of the solution provided by CPPforSchool. See below.
With that said, I quickly created a similar project that virtually mimicked the source. I changed the variable names from a, b, c, greatest to x, y, z, bignum. It appears that I simply need to practice more in order to have a stronger understanding of ternary operators. The code is more compact, but quite difficult to read, especially from a novice perspective. After a few YouTube videos, it became quite apparent that I was not the only one who felt this struggle with ternary operators. It makes sense. Reading if/else statements are far easier to comprehend at a glance over the use of question marks and colons to separate conditions and executable code.
Comments
Post a Comment