Browse Source

Add C++ to list

master
Matei-Alexandru Gardus 9 months ago
parent
commit
f3ae772050
No known key found for this signature in database
2 changed files with 42 additions and 1 deletions
  1. 2
    1
      README.md
  2. 40
    0
      isEven.cpp

+ 2
- 1
README.md View File

@@ -5,4 +5,5 @@ I like getting a feel for whatever language I think would work best for a specif
5 5
 This is a Git repository of elementary algorithm programs for every language I know so that I can see which one I like best.
6 6
 
7 7
 ## Programming Languages List
8
-- C
8
+- C
9
+- C++

+ 40
- 0
isEven.cpp View File

@@ -0,0 +1,40 @@
1
+#include <iostream>
2
+
3
+/* "Even number check"
4
+ *
5
+ * C++ was the second programming language I ever learned, and I did because I wanted to study Object-Oriented Programming.
6
+ * God, I was stupid back then.
7
+ * 
8
+ * Frankly, I'll admit: I picked this language back then to study next because I was too much of a wuss to try any other one.
9
+ * I thought it would be similar to C and not be a completely different language to spook me out. I was not wrong, but not
10
+ * right either.
11
+ * 
12
+ * Templates are hell to try to write, and this program will completely avoid them. But the classes are a nice touch to C that
13
+ * I really like. Plus, C++ was actually the language I used for schoolwork, not C. So I guess C++ brings me the bad memories.
14
+ * 
15
+ * This algorithm just checks for an even number from standard input. Simple enough.
16
+ */
17
+
18
+bool isEven(long long int x)
19
+{
20
+    if (x % 2 == 0) 
21
+    {
22
+        return true;
23
+    } else {
24
+        return false;
25
+    }
26
+}
27
+
28
+int main()
29
+{
30
+    long long int x;
31
+    std::cout << "Gimme an even number: ";
32
+    std::cin >> x;
33
+    if (isEven(x))
34
+    {
35
+        std::cout << "That's an even number! Well done!";
36
+    } else {
37
+        std::cout << "You donut, that isn't even. What are you doing with your life?";
38
+    }
39
+    return 0;
40
+}

Loading…
Cancel
Save