add if/else, arrays, vectors & while/for loops
This commit is contained in:
parent
3d8100ef37
commit
df3b9fa2c6
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
.vscode*
|
14
array.cpp
Normal file
14
array.cpp
Normal 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;
|
||||
}
|
19
if_else.cpp
Normal file
19
if_else.cpp
Normal 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!";
|
||||
}
|
||||
}
|
BIN
vars_pointers
BIN
vars_pointers
Binary file not shown.
25
vector.cpp
Normal file
25
vector.cpp
Normal 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";
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user