HAN23080099
HAN23080099
Task 1,2,3
#include <iostream>
int main()
cout << "The player's name is " << name << endl;
cout << "The player's age is " << age << endl;
cout << "The player's height is " << height << endl;
cout << "The player's skill tier is " << tier << endl;
//updating variables
name = "Alex";
age = 19;
height = 1.7;
tier = 'A';
subscription = false;
cout << "The player's name is " << name << endl;
cout << "The player's age is " << age << endl;
cout << "The player's height is " << height << endl;
cout << "The player's skill tier is " << tier << endl;
return 0;
}
Challenge 2 Loops and Conditionals
Task 1
#include <iostream>
int main() {
int Input;
case 1:
cout << "Nearly all wild lions live in Africa, but one small population exists elsewhere" << endl;
break;
case 2:
cout << "Dogs are the most popular pet on the planet!" << endl;
break;
case 3:
cout << "The oldest known pet cat existed 9,500 years ago." << endl;
break;
case 4:
cout << "Capybaras are the largest rodents in the world." << endl;
break;
case 5:
cout << "Bears are big, strong, and fast!" << endl;
break;
default:
break;
return 0;
}
Task 2
#include <iostream>
int main() {
int inputNumber;
cout << "All even numbers between 2 and " << inputNumber << " are :" << endl;
return 0;
}
Task 3
#include <iostream>
int main() {
int base;
int exponent;
bool choice = 1;
//Exponent calculator
while (choice == 1) {
int result = 1;
cout << "Enter an exponent number (the number must be lower than or equal to 5):";
result *= base;
cout << base << "^" << exponent << " equals " << result <<endl;
}
else{
cout << "exponent must be lower than or equal to 5" << endl;
break;
cout << "Would you like to go again? (1) Yes or (0) No" << endl;
return 0;
Challenge 3 Functions
Task 1
#include <iostream>
using namespace std;
void start(){
int subtract(){
int firstNum;
int secondNum;
cout << firstNum << " - " << secondNum << " equals " << result << endl;
return result;
void checkResult(){
else {
int main() {
start();
checkResult();
return 0;
}
Task 2
#include <cstdlib>
#include <iostream>
int main() {
int lowest;
int highest;
int count;
srand(time(NULL));
return 0;
Task 3
#include <cstdlib>
#include <iostream>
int numGen() {
int min = 0;
srand(time(NULL));
return genNum;
//Game's rules
void game(){
int guess;
bool correct = 0;
int answer = numGen();
else {
correct = 1;
int main(){
game();
return 0;
}
Challenge 4 Strings
Task 1
#include <iostream>
//Questions 1-5
int ask()
string ans1;
//result
if (ans1 == "London") {
return 1;
else {
return 0;
int ask2()
string ans1;
if (ans1 == "Hanoi") {
return 1;
else {
return 0;
int ask3()
string ans1;
cout << "Question 3:" << endl;
if (ans1 == "Berlin") {
return 1;
else {
return 0;
int ask4()
string ans1;
if (ans1 == "Tokyo") {
return 1;
else {
return 0;
int ask5()
{
string ans1;
if (ans1 == "Canberra") {
return 1;
else {
return 0;
//The Program
int main() {
while (choice == 1) {
if (ask() == 1) {
if (ask2() == 1) {
if (ask3() == 1) {
if (ask4() == 1) {
if (ask5() == 1) {
}
else{}
cout << "Do you want to play again: (1 for yes, 0 for no)" << endl;
Task 2
#include <iostream>
#include <cstdlib>
#include <string>
int main() {
string username;
//NumberGenerator
srand(time(NULL));
username.append("#" + to_string(ranNum));
return 0;
Task 3
#include <iostream>
#include <cstdlib>
#include <string>
int main() {
string userName;
string userNameNew;
cout << "Enter your username:";
//profanity check
if (userName.find(profanity) == -1) {
else {
Challenge 5 Program
Task 1
#include<cstdlib>
#include<string>
#include<iostream>
//public Variables
string sCPUstr;
int sPlayerPoint = 0;
int sCPUPoint = 0;
int cpuNum() {
srand(unsigned(time(NULL)));
return cpuNum;
void converter() {
switch (cpuNum()) {
case 1:
sCPUstr = "water";
break;
case 2:
sCPUstr = "fire";
break;
case 3:
sCPUstr = "earth";
break;
}
void game() {
string sInput;
cout << "The computer chose " << sCPUstr << endl;
if (sInput == sCPUstr) {
else if ((sInput == "earth" && sCPUstr == "water") || (sInput == "fire" && sCPUstr == "earth") ||
(sInput == "water" && sCPUstr == "fire")) {
sPlayerPoint++;
else {
sCPUPoint++;
//main program
int main() {
while (sPlayingGame == 1) {
sPlayerPoint = 0;
sCPUPoint = 0;
while ((sPlayerPoint < 3) && (sCPUPoint < 3) ) {
converter();
game();
if (sPlayerPoint == 3) {
sPlayingGame = 0;
if (sCPUPoint == 3) {
sPlayingGame = 0;
cout << "Play again? (1) Yes or (0) No" << endl;