-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCppCodeBits.cpp
More file actions
80 lines (62 loc) · 1.15 KB
/
CppCodeBits.cpp
File metadata and controls
80 lines (62 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Code Bit #1
// beginner's template for Writing C++ code in main function
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World!\n";
return 0;
}
// End Code Bit #1
// Code Bit #2
// Template for creating an if-else statement
#include <iostream>
using namespace std;
int main()
{
int num = 1;
if(num == 2)
{
cout << "Num = 2";
}
else if(num == 1)
{
cout << "Num = 1";
}
else
{
cout << "Num does not equal 1 or 2.";
}
return 0;
}
// End Code Bit #2
// Code Bit #3
// Template for a for-loop
#include <iostream>
using namespace std;
int main()
{
int iterations = 10;
for(int inc = 0; inc < iterations; inc++)
{
cout << "We are have looped " << inc << " times!" << endl;
}
return 0;
}
// End Code Bit #3
// Code Bit #4
// Template for while loop
#include <iostream>
using namespace std;
int main()
{
int iterations = 10;
int inc = 0;
while(inc < iterations)
{
cout << "Loop " << inc << endl;
inc++; // Incrementing the counter
}
return 0;
}
// End Code Bit #4