I'm a first semester C++ student trying to make a program where, given 3 int values it finds the sum. However, if one of the values is the same as another of the values, it does not count towards the sum The problem comes in the if / else if part of my code.
When I run it an enter something like 1, 1, 2 it should only add 1 and two but instead outputs hundreds of lines of garbage code. I don't know what I did or what I should be doing as there aren't any errors. Entering 1, 1, 1 should and does output 1, but anything outside of that use case fails.
My code is:
#include <iostream>
#include <stdlib.h>
using namespace std;
// Declare Function:
string loneSum(int num1, int num2, int num3);
int main()
{
//Declaring vars
int num1;
int num2;
int num3;
//Obtaining user input
cout << "Please enter number one: ";
cin >> num1;
cout << "Please enter number two: ";
cin >> num2;
cout << "Please enter number two: ";
cin >> num3;
cout << loneSum(num1, num2, num3);
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Sends user input to function
}
string loneSum(int num1, int num2, int num3) {
if(num1 != num2 || num3) {
cout << num1 + num2 + num3;
}
else if ((num1 == num2) && (num2 != num3)) {
cout << num2 + num3;
}
else if ((num2 == num3) && (num3 != num1)) {
cout << num1 + num3;
}
else if (num1 == num2 && num3) {
cout << "None";
}
}