add if/else, arrays, vectors & while/for loops

This commit is contained in:
Kishan Takoordyal 2020-11-13 10:06:37 +04:00
parent 3d8100ef37
commit df3b9fa2c6
10 changed files with 78 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.vscode*

BIN
array Executable file

Binary file not shown.

14
array.cpp Normal file
View File

@ -0,0 +1,14 @@
#include <iostream>
using namespace std;
int main() {
string alphabets[] = {"a", "b", "c", "d"};
int primeNumbers[4];
primeNumbers[0] = 2;
primeNumbers[1] = 3;
primeNumbers[2] = 5;
primeNumbers[3] = 7;
}

BIN
if_else Executable file

Binary file not shown.

19
if_else.cpp Normal file
View File

@ -0,0 +1,19 @@
#include <iostream>
using namespace std;
int main() {
int health;
int maxHealth = 100;
cout << "Input current health: ";
cin >> health;
if (health <= maxHealth / 4) {
cout << "Health low!";
} else if (health <= maxHealth / 2) {
cout << "Be careful!";
} else {
cout << "Going great!";
}
}

Binary file not shown.

BIN
vector Executable file

Binary file not shown.

25
vector.cpp Normal file
View File

@ -0,0 +1,25 @@
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<string> inventory;
inventory.push_back("sword");
inventory.push_back("shield");
inventory.push_back("boots");
inventory.pop_back();
string front = inventory.front();
cout << "First element in inventory: " << front << "\n";
string back = inventory.back();
cout << "Last element in inventory: " << back << "\n";
cout << "\n";
for (int i = 0; i < inventory.size(); i++) {
cout << i << ": " << inventory[i] << "\n";
}
}

BIN
while Executable file

Binary file not shown.

19
while.cpp Normal file
View File

@ -0,0 +1,19 @@
#include <iostream>
using namespace std;
int main() {
int xPos = 0;
int endPos = 10;
while (true) {
xPos++;
cout << xPos << '\n';
if (xPos >= endPos) {
break;
}
}
cout << "Game Over! \n";
}