
I began the program by using <iostream>, <string>, and <fstream>, which allowed me to input and output not only words and variables but also files. The program did not use a string, but in order to remember to include it when needed, I placed in in anyways. "Using namespace std;" allowed us to avoid using "std::" throughout the program whenever working with data. I streamed in the file and proceeded to define my variables. I established all of them as "float" as opposed to "double" because "float" allows for real numbers with less space taken up. Since the values were not as large size wise, using "double" for the particular set of data would not have been as efficient space wise (but for larger numbers "double" could also be used). The large numbers were defined as 0 and the "min" was defined as 99999 so that the numbers could get larger and smaller, respectively. However, the while loop was the star of the show. It's function let the data be run and adjust the min and max. The if and else if statements allowed the program to change the answers when presented with a criteria meeting number. If the following value exceeded the previous, it became the new max; on the other hand, if the value was less than the previous it became the new min. The sum was established by adding the previous term with the one following. Additionally, the variable "moo" added 1 to itself each time a new number came by (moo++). This made finding the average from the sum simple to get. The program goes to state all the values obtained whenever run: the min, the max, the sum, and the average. Equally important, to conclude the program, the data was exported to a file of its own which contained the answers as well. This was done by using ofstream and creating a new text file.
The program did not always run smoothly. After trying to run it the first time, the program shot out error messages across the program. I naively placed semi-colons where there was no need to. Thankfully, the program shot out errors and indicated the lines where the issue was. This helped to remedy the problem quicker. Near completion, the monitor also displayed each answer as it was modifying what the answer was. To further clarify, each time the program tested whether a number was larger or smaller than the previous (to find the min and max), the program spit out each answer as it went down the list of numbers. Upon further investigation, it became apparent that the key error was placing the "cout" inside of the loop; it therefore spit out the answer each time it checked a new number. The solution here was to put all the "cout"'s outside the loop.
With each corrected mistake I take an additional step forward in becoming a programming master.

No comments:
Post a Comment