Professional Documents
Culture Documents
Beginners Course Programming Using C++: Sybrand
Beginners Course Programming Using C++: Sybrand
using C++
Sybrand
Language Sloth
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Editor:
You can use any editor you want!
Good option: VSCode
Something like notepad also works
Compiler:
Windows: install MinGW
MacOS: install clang via Xcode
Linux: install gcc via your package manager
I might do a tutorial on installing later, for now either use
cplayground.com or lookup installation instructions.
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Write a quiz!
if and if-else statements
New variable type: bool
Boolean logic (conditions)
for loops
while loops
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
int main() {
int correct = 0;
string answer;
if (correct == 0) {
cout << ”Next time better luck, you didn't answer any question correctly.” << endl;
} else {
cout << ”Good job, you correctly answered ” << correct << ” questions.” << endl;
}
return 0;
}
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Condition:
// These are the variables the condition will use.
bool a, b;
int c, d;
bool is_equal = c == d;
bool is_not_equal = !(c == d);
bool is_not_equal_2 = c != d;
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
int main() {
int correct = 0;
string answer;
if (correct == 0) {
cout << ”Next time better luck, you didn't answer any question correctly.” << endl;
} else {
cout << ”Good job, you correctly answered ” << correct << ” questions.” << endl;
}
return 0;
}
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
#include <iostream>
using namespace std;
int main() {
int amount;
return 0;
}
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
int main() {
int amount;
cout << ”How many numbers do you want to sum?” << endl;
cin >> amount;
int sum = 0;
for (int i = 1; i <= amount; i = i+1) {
// Does the same as: sum = sum + i;
sum += i;
return 0;
}
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
int main() {
int amount;
cout << ”How many numbers do you want to input?” << endl;
cin >> amount;
int biggest = 0;
for (int i = 0; i < amount; i++) {
int number;
cin >> number;
return 0;
} . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
// Increment i
i++;
}
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .