Ok,
so for my beginner C++ class, I was instructed to write a program with a bool function that returns true if the sum of two integers is greater than 10, and false if it is less than or equal to 10. For some reason, even when the sum is less than 10, it always returns true and says the sum is greater than 10. Any help is appreciated, thanks.
It looks like you wrote:
if(true)
{
cout<<"The sum is greater than 10"<<endl;
}
if(true) will always evaluate to true and it will always output "the sum is greater than 10"
Instead of what you wrote, use:
bool morethanten = sumthemup(first,second);
if(morethanten)
{
cout << "True" << endl;
}
Secondly, in sunthemup(int first, int second) you wrote:
first + second == sum;
It should be: first + second = sum;
You were using the comparison operator, not the assignment operator.
You were also putting "sum" on the wrong side; you should do it like this:
sum = first + second.
Now the program should work.