diff options
author | RossTheRoss <msattr@gmail.com> | 2019-03-10 16:29:27 -0500 |
---|---|---|
committer | RossTheRoss <msattr@gmail.com> | 2019-03-10 16:29:27 -0500 |
commit | 2ea7b443b2653a50c81063bee1ff9ca4efcab2d1 (patch) | |
tree | 8fef3aa40c3bf4c8b0389459ee6f21aac2af213e /ee1301 | |
parent | Fix an oopsie-woopsie (diff) | |
download | homework-2ea7b443b2653a50c81063bee1ff9ca4efcab2d1.tar homework-2ea7b443b2653a50c81063bee1ff9ca4efcab2d1.tar.gz homework-2ea7b443b2653a50c81063bee1ff9ca4efcab2d1.tar.bz2 homework-2ea7b443b2653a50c81063bee1ff9ca4efcab2d1.tar.lz homework-2ea7b443b2653a50c81063bee1ff9ca4efcab2d1.tar.xz homework-2ea7b443b2653a50c81063bee1ff9ca4efcab2d1.tar.zst homework-2ea7b443b2653a50c81063bee1ff9ca4efcab2d1.zip |
Rearrange some error checking
Diffstat (limited to 'ee1301')
-rw-r--r-- | ee1301/wk4/hw4_directory/strap012_HW4A.cpp | 14 | ||||
-rw-r--r-- | ee1301/wk4/hw4_directory/strap012_HW4C.cpp | 12 |
2 files changed, 13 insertions, 13 deletions
diff --git a/ee1301/wk4/hw4_directory/strap012_HW4A.cpp b/ee1301/wk4/hw4_directory/strap012_HW4A.cpp index abedc7a..12556ba 100644 --- a/ee1301/wk4/hw4_directory/strap012_HW4A.cpp +++ b/ee1301/wk4/hw4_directory/strap012_HW4A.cpp @@ -22,6 +22,13 @@ int main () { std::cout << "File read failed!\n"; return -1; } + fout.open("output_files/statistics.csv"); + if (!fout.is_open()) + { + std::cout << "File write failed!\n"; + return -2; + } + while (fin >> garbage >> garbage >> score) { getline(fin, garbage); //Any decimals are not needed and will be culled if (score>90) { @@ -42,13 +49,6 @@ int main () { << D << " D" << std::endl << F << " F" << std::endl; fin.close(); - - - fout.open("output_files/statistics.csv"); - if (!fout.is_open()) { - std::cout << "File write failed!\n"; - return -2; - } fout << "Grade, NumStudents" << std::endl << "A," << A << std::endl << "B," << B << std::endl diff --git a/ee1301/wk4/hw4_directory/strap012_HW4C.cpp b/ee1301/wk4/hw4_directory/strap012_HW4C.cpp index 17ef381..e6825dc 100644 --- a/ee1301/wk4/hw4_directory/strap012_HW4C.cpp +++ b/ee1301/wk4/hw4_directory/strap012_HW4C.cpp @@ -22,6 +22,12 @@ int main() std::cout << "File read failed!\n"; return -1; } + fout.open("output_files/election_results.txt"); + if (!fout.is_open()) + { + std::cout << "File write failed!\n"; + return -2; + } while (fin >> Char) { if (Char=='A' || Char=='a') { A++; @@ -56,12 +62,6 @@ int main() << "The winner is the letter \"" << winner << "\"!" << std::endl; - - fout.open("output_files/election_results.txt"); - if (!fout.is_open()) { - std::cout << "File write failed!\n"; - return -2; - } fout << "A," << A << std::endl << "E," << E << std::endl << "I," << I << std::endl |