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

Assignment submission #4

Open
wants to merge 5 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
10 changes: 4 additions & 6 deletions fix-code-0/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@ int main() {
if (is_student) {
if (is_cs_student) {
cout << "Excellent they are learning amazing things!";
} else
if (is_math_student) {
}
else if (is_math_student) {
cout << "Hmm, glad there learning something.";
}
else {
cout << "Well I hope they are enjoying what they are learning."
cout << "Well I hope they are enjoying what they are learning. It seems like they should be back in school!";
}
} else {
cout << "It seems like they should be back in school!"
}
}
return 0;
}
12 changes: 10 additions & 2 deletions fix-code-1/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,21 @@ using namespace std;
float GetAbsoluteValue(const float input) {
if (input < 0) {
return -1 * input;
} else (input >= 0) {
}
else {
return input;
}
}

float GetUserInput() {
float value;
cout << "Value: ";
cin >> value;
return value;
}

int main() {
float value = GetUserInput();
cout << "The absolute value is: " << GetAbsoluteValue(value);
cout << "The absolute value is: " << GetAbsoluteValue(value) << endl;
return 0;
}
34 changes: 31 additions & 3 deletions fix-code-2/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,42 @@
#include <string>
using namespace std;


char GetLetterFromUser() {
char letter;
cout << "Lowercase Letter: ";
cin >> letter;
return letter;
}

bool IsVowel(char letter) {
if (letter == 'e') {
return true;
}
else if (letter == 'i') {
return true;
}
else if (letter == 'o') {
return true;
}
else if (letter == 'u') {
return true;
}
else {
return false;
}
}

int main() {
char letter = GetLetterFromUser();

else if (letter == 'a') {
if (letter == 'a') {
cout << "The letter is the first letter in the alphabet.";
} if (IsVowel(letter)) {
}
else if (IsVowel(letter)) {
cout << "The letter is a vowel.";
} else {
}
else {
cout << "The letter is not a.";
}
return 0;
Expand Down
8 changes: 5 additions & 3 deletions fix-code-3/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ int main() {

if (needs_engine) {
cost_of_repairs = cost_of_repairs + engine_cost;
} else if (needs_breaks) {
}
if (needs_breaks) {
cost_of_repairs = cost_of_repairs + breaks_cost;
} else if (needs_windshield) {
}
if (needs_windshield) {
cost_of_repairs = cost_of_repairs + windshield_cost;
}

cout << "The total repair costs will be: " << cost_of_repairs;
return 0;
}
62 changes: 35 additions & 27 deletions fix-code-4/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,41 @@
#include <string>
using namespace std;

int main() {
int number = get_user_input();

int value = 0;
if (number % 1 == 0) {
value++;
}
if (number % 2 == 0) {
value++;
}
if (number % 3 == 0) {
value--;
}
if (number % 4 == 0) {
value++;
}
if (number % 5 == 0) {
value++;
}
if (number % 6 == 0) {
value++;
}
if (number % 7 == 0) {
value++;
int getUserInput() {
int number;
cout << "Number: ";
cin >> number;
return number;
}

cout << "The number of multiples less than 10 for " << number " is: " << value << endl;

return 0;
}
int main() {
int number = getUserInput();

int value = 0;
if (number % 1 == 0) {
value++;
}
if (number % 2 == 0) {
value++;
}
if (number % 3 == 0) {
value--;
}
if (number % 4 == 0) {
value++;
}
if (number % 5 == 0) {
value++;
}
if (number % 6 == 0) {
value++;
}
if (number % 7 == 0) {
value++;
}

cout << "The number of multiples less than 10 for " << number << " is: " << value << endl;

return 0;
}
27 changes: 21 additions & 6 deletions invent-code-0/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,28 @@
using namespace std;

// If both value_one and value_two are positive, increment and return output. If not decrement and return output.
int CheckAllPositive(const float value_one, const float value_two, int output) {
// Write code here.
int checkAllPositive(const float value_one, const float value_two, int output) {
if (value_one > 0 && value_two > 0) {
output++;
return output;
} else {
output--;
return output;
}
}

// If the product of value_one and value_two is greater than the sum, increment and return output. If that is not true, but the sum of value_one and value_two is greater than zero, decrement output and return it. If neither of those is true, return 0.
int EvaluateScale(const float value_one, const float value_two, int output) {
// Write code here.
int evaluateScale(const float value_one, const float value_two, int output) {
float sum = value_one + value_two;
if ((value_one * value_two) > sum) {
output++;
return output;
} else if (sum > 0) {
output--;
return output;
} else {
return 0;
}
}

// Given a number print out a single fortune for a user.
Expand All @@ -36,8 +51,8 @@ int main() {
cout << "Enter another number please: ";
cin >> value_two;

counter = CheckAllPositive(value_one, value_two, counter);
counter = EvaluateScale(value_one, value_two, counter);
counter = checkAllPositive(value_one, value_two, counter);
counter = evaluateScale(value_one, value_two, counter);

PrintFortune(counter);

Expand Down
53 changes: 53 additions & 0 deletions invent-code-1/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,59 @@
#include <string>
using namespace std;

int evaluator(int number) {
int value = 0;
if (number % 1 == 0) {
value++;
cout << "1, ";
}
if (number % 2 == 0) {
value++;
cout << "2, ";
}
if (number % 3 == 0) {
value++;
cout << "3, ";
}
if (number % 4 == 0) {
value++;
cout << "4, ";
}
if (number % 5 == 0) {
value++;
cout << "5, ";
}
if (number % 6 == 0) {
value++;
cout << "6, ";
}
if (number % 7 == 0) {
value++;
cout << "7, ";
}
if (number % 8 == 0) {
value++;
cout << "8, ";
}
if (number % 9 == 0) {
value++;
cout << "9, ";
}
if (number % 10 == 0) {
value++;
cout << "10, ";
}
return value;
}


int main() {
int number;
cout << "Number: ";
cin >> number;
int value = evaluator(number);
cout << endl << "Multiples: " << value << endl;
return 0;
}