Welcome to my first attempt at the beginner exercises I found on cplusplus.com. Hopefully you can bear with me for some of the most asinine mistakes I made on this project. As a frame of reference, my only experience is with java and that was in college during Compsci 101; almost 2 years ago. You could rate my knowledge as little to none, so don’t ever let anybody tell you that you can’t learn c++ and don’t be afraid to make mistakes. I will post all my programs and the source code at the end of the blog if you want to see my train of thought or edit them yourself ( FYI, my organizational scheme is “name”V.R, where V is the version and R is the revision for referencing).
The grading problem is as follows:
Requires: variables, data types, and numerical operators
basic input/output
logic (if statements, switch statements)
Write a program that allows the user to enter the grade scored in a programming class (0-100).
If the user scored a 100 then notify the user that they got a perfect score.
★ Modify the program so that if the user scored a 90-100 it informs the user that they scored an A
★★ Modify the program so that it will notify the user of their letter grade
0-59 F 60-69 D 70-79 C 80-89 B 90-100 A
The premise of this problem is very simple; enter a numerical score for a grade on the exam and if they scored a 100 tell them they made a perfect score. Since they didn’t specify to check that the score is between 0 and 100 I decided to leave that out for now. (Maybe that will be an extra ★★★ reward.) I decided to tackle this problem in 3 versions: Check if they made a 100, add the first star challenge, and add the second start challenge.
I started simple with the program grade whose sole purpose was to ask the user for input, compare it, and then output. After compiling and holding my breath, since even my most basic programs like to throw errors, its time to run it. I first tested with 100 and 99, but to my surprise, they both work! Time to begin work on grade1.0.
My first train of thought was that I needed an else statement or the if statement would always execute. (Even I thought that that didn’t sound right.) So lets run it “once more again” and get the same exact output… time for grade1.1!
This is when I decided to ask google for help and learned that = != ==. With this newly discovered knowledge the rest of this program would be a breeze. Or so I thought.
On to 2.0 and and its time to add some extra features. I decided to use a quick and dirty fix to satisfy the conditions. I replaced (grade == 100) with (grade > 90). Compile, test and success!
Its finally time to bring the whole project together and implement everything learned with grade3.0. This is where I made a majority of my errors and learned a few lessons along the way. I decided to use if statements with two conditions to check each threshold. The program worked, but it worked a little too well with a score of 100 outputting a grade of A,B,C,D, and failed.
The addition of grade3.1 brought with it the knowledge that the operator || means OR and the operator && means AND. At this point I feel pretty stupid and hastily test my program again. This time I get the correct answer but also get “you failed”.
Another revision and we’re up to grade3.2 and my haste I devised a simple fix; just delete the else statement and everything will be fine. This would have worked if the “you failed” came from the else statement. I then realized that I used the wrong operation to check if the score was below sixty and thus 3.3 is born!
However, 3.3 was short lived and else statement was removed once more making version 3.4.
While testing 3.4 I discovered that numbers 90-100 worked correctly, however, 89 would output a grade of B and C. Easily enough it was another typo’d operation and finally grade3.5 is running smoothly!
In closing, with basic knowledge and some trial and error, any task can be accomplished. I find that making mistakes and learning from them is a better learning tool than just copying some example projects and trying to decipher how they work. This style, in my personal opinion, helps you learn not why a program works, but how a program works.
Thank you for reading my story about my struggles with the C++ language and I hope you got a few laughs along the way. If you want to play with the source or run the code yourselves, you can find the whole project here. Stay tuned for more!