long sum ( int m, int n )
{
int o = 0;
int p = m;
if (p > n)
(o = 0);
else (p <= n)
(o = o + p), p++;
cout << "The sum of all integers between " << m << "and " << n << "is: " << o << "." << endl;
}
DevC++ tells me that in line 9 "(p <= n) cannot be used as a function". What's the problem? It's a normal logical operator that I've used in small programs before.
Of course, thanks. Wood for the trees and all that. I've always been absolutely hopeless at programming, but it's my first session at university and I'm trying not to fail. I tend to test things as I go as well, rather than waiting until I've got a complete module. And of course an if-else is stupid as you say, no loop. What about adding a while loop:
1 2 3 4 5 6 7 8
if (p > n)
(o = 0);
elsewhile (p <= n)
{
(o += p);
p++;
}