Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Now the program uses subtracting (-) operator to choose the winner #55

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 7 additions & 54 deletions 3-conditionals-and-logic/rock-paper-scissors-lizard-spock/RPS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,63 +36,16 @@ int main() {
std::cout << "cpu choose: ✌️\n";


if (user == computer) {

std::cout << "it's a tie!\n";

}

// user rock

else if (user == 1) {

if (computer == 2) {

std::cout << "you lost! booooo!\n";

}
if (computer == 3) {

std::cout << "you won! woohoo!\n";

}

if ((user - computer == 1) || (user - computer == -2)) {
std::cout << "YEAH!!! You won!" << std::endl;
}

// user paper

else if (user == 2) {

if (computer == 1) {

std::cout << "you won! woohoo!\n";

}
if (computer == 3) {

std::cout << "you lost! boo!\n";

}

else if ((user - computer == -1) || (user - computer == 2)) {
std::cout << "OH!!! Computer won!" << std::endl;
}

// user scissors

else if (user == 3) {

if (computer == 1) {

std::cout << "you won! woohoo!\n";

}
if (computer == 2) {

std::cout << "you lost! booooo!\n";

}

else {
std::cout << "It's a tie!" << std::endl;
}

return 0;

}
9 changes: 4 additions & 5 deletions 7-classes-and-objects/app.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#include <iostream>

#include "profile.hpp"

int main() {

Profile sam("Sam Drakkila", 30, "New York", "USA", "he/him");

sam.add_hobby("listening to audiobooks and podcasts");
sam.add_hobby("playing rec sports like bowling and kickball");
sam.add_hobby("writing a speculative fiction novel");
sam.add_hobby("reading advice columns");
std::cout << sam.view_profile();

}
std::cout << sam.view_profile();
}
29 changes: 7 additions & 22 deletions 7-classes-and-objects/profile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,21 @@

#include "profile.hpp"

Profile::Profile(std::string new_name, int new_age, std::string new_city, std::string new_country, std::string new_pronouns)
: name(new_name), age(new_age), city(new_city), country(new_country), pronouns(new_pronouns) {

if (new_age >= 18) {
age = new_age;
} else {
age = 0;
}

Profile::Profile(const std::string new_name, const int new_age, const std::string new_city, const std::string new_country, const std::string new_pronouns) : name(new_name), age(new_age), city(new_city), country(new_country), pronouns(new_pronouns) {
}

std::string Profile::view_profile() {
std::string hobbies_str = "";

std::string bio = "Name: " + name;
bio += "\nAge: " + std::to_string(age);
bio += "\nPronouns: " + pronouns;
std::string hobby_string = "Hobbies:\n";

for (std::string hobby : hobbies) {

hobby_string += " - " + hobby + "\n";

for (const std::string &hobby : hobbies) {
hobbies_str += hobby + ", ";
}

return bio + "\n" + hobby_string;
hobbies_str = hobbies_str.substr(0, hobbies_str.length() - 2);

return name + " is " + std::to_string(age) + " years old and " + pronouns.substr(0, pronouns.find("/")) + " lives in " + city + " city, " + country + ".\n" + "Hobbies : " + hobbies_str + "\n";
}

void Profile::add_hobby(std::string new_hobby) {

void Profile::add_hobby(const std::string &new_hobby) {
hobbies.push_back(new_hobby);

}
26 changes: 13 additions & 13 deletions 7-classes-and-objects/profile.hpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#include <string>
#include <vector>

class Profile {
private:
std::string name;
int age;
std::string city;
std::string country;
std::string pronouns;
std::vector<std::string> hobbies;
private:
std::string name;
int age;
std::string city;
std::string country;
std::string pronouns;
std::vector<std::string> hobbies;

public:
Profile(std::string new_name, int new_age, std::string new_city, std::string new_country, std::string new_pronouns = "they/them");
std::string view_profile();
void add_hobby(std::string new_hobby);

};
public:
Profile(const std::string new_name, const int new_age, const std::string new_city, const std::string new_country, const std::string new_pronouns = "they/them");
void add_hobby(const std::string &new_hobby);
std::string view_profile();
};