summaryrefslogtreecommitdiffstats
path: root/C++/cinErrorExample
diff options
context:
space:
mode:
authormsglm <msglm@techchud.xyz>2023-01-14 05:31:48 -0600
committermsglm <msglm@techchud.xyz>2023-01-14 05:31:48 -0600
commit9d53d8857eaa1c9405894a88ca75bc4657e42f35 (patch)
treeeb1efc1d028b949dd83bb710c68be8eff58f26e7 /C++/cinErrorExample
downloadschool-code-master.tar.gz
school-code-master.tar.bz2
school-code-master.zip
Inital CommitHEADmaster
Diffstat (limited to 'C++/cinErrorExample')
-rw-r--r--C++/cinErrorExample/cinErrorExample output(1).docxbin0 -> 56355 bytes
-rw-r--r--C++/cinErrorExample/cinErrorExamples.cpp42
2 files changed, 42 insertions, 0 deletions
diff --git a/C++/cinErrorExample/cinErrorExample output(1).docx b/C++/cinErrorExample/cinErrorExample output(1).docx
new file mode 100644
index 0000000..7c8196b
--- /dev/null
+++ b/C++/cinErrorExample/cinErrorExample output(1).docx
Binary files differ
diff --git a/C++/cinErrorExample/cinErrorExamples.cpp b/C++/cinErrorExample/cinErrorExamples.cpp
new file mode 100644
index 0000000..741e987
--- /dev/null
+++ b/C++/cinErrorExample/cinErrorExamples.cpp
@@ -0,0 +1,42 @@
+// Program: cin error examples
+// Ch 3: Input/Output
+
+// The purpose of this program is to look at some possible errors
+// that might occur if a user enters incorrect input
+
+#include <iostream>
+
+using namespace std;
+
+int main()
+{
+ int int1, int2;
+ double dbl;
+ char ch;
+
+ cout << "TESTING INPUT ERRORS" << endl;
+ cout << "Tested by: Anonymous" << endl;
+ cout << "This program is designed to read 2 integer values, followed \n";
+ cout << "by a double value, followed by a character value.\n\n";
+
+ /* INPUT FAILURE & FAIL STATE
+ An attempt to read invalid data, such as trying to put a letter into an int
+ or double, results in input failure. The input stream enters a state called
+ the "fail state." Once it enters fail state, all further I/O statements using
+ that stream are ignored. However, the program continues to execute with whatever
+ values are stored in variables and produces incorrect results.
+ */
+
+ // Run this program several times and purposely provide wrong data types
+ // to see what kind of output is produced.
+ cout << "Input, separated by spaces: ";
+ cin >> int1 >> int2 >> dbl >> ch;
+
+ // Output
+ cout << "int: " << int1 << endl;
+ cout << "int: " << int2 << endl;
+ cout << "Double: " << dbl << endl;
+ cout << "char: " << ch << endl;
+
+ return 0;
+}