CPPForSchool.com: Variable, Operator & Expression Set 2: Assignment 4
4.
Write a program which accepts a character and display its next character.
This assignment was a lot of fun. Mainly because it came rather intuitively. However, I had to review my prior assignment that dealt with ASCII. Nevertheless, my approach to this assignment was to take the user's character input, followed by determining the ASCII value. From there, it was a matter of placing the ASCII value into a new variable, adding 1, and then outputting the character value.
With great surprise, everything worked out smoothly.
Of course, I am not completely convinced so I tested it once more. Eureka! The program worked flawlessly.
Of course, I always compare my code to the example code. With that said, I discovered that there was a much easier method of coding this assignment. Instead of converting the character to ASCII and then adding one while utilizing two variables, I can handle all of this with one variable without any conversions.
Below is the updated source code, which is compact and clean. However, I am quite pleased with the overall outcome because I have ultimately discovered more than one way to code this particular task. Perhaps in the future, my method would serve a better purpose, in regards to flexibility of the code.
This assignment was a lot of fun. Mainly because it came rather intuitively. However, I had to review my prior assignment that dealt with ASCII. Nevertheless, my approach to this assignment was to take the user's character input, followed by determining the ASCII value. From there, it was a matter of placing the ASCII value into a new variable, adding 1, and then outputting the character value.
With great surprise, everything worked out smoothly.
Of course, I am not completely convinced so I tested it once more. Eureka! The program worked flawlessly.
Of course, I always compare my code to the example code. With that said, I discovered that there was a much easier method of coding this assignment. Instead of converting the character to ASCII and then adding one while utilizing two variables, I can handle all of this with one variable without any conversions.
Below is the updated source code, which is compact and clean. However, I am quite pleased with the overall outcome because I have ultimately discovered more than one way to code this particular task. Perhaps in the future, my method would serve a better purpose, in regards to flexibility of the code.
Comments
Post a Comment