# Not sure why this failed

This is a discussion on Not sure why this failed within the C++ Programming forums, part of the General Programming Boards category; Originally Posted by ZuK Did I ?. The op already had a solution that gives the same results. Kurt no ...

1. Originally Posted by ZuK
Did I ?. The op already had a solution that gives the same results.
Kurt
no solution here your code didn't work either. although much better. I seem to start with some sort of structure but I end up hacking it to make it fit, making it less user friendly.

2. Originally Posted by oogabooga
Okay. So that stuff needs to be there exactly like that.
What about the lack of a newline after printing sum
Code:
`cout << sum;`
Try
Code:
`cout << sum << endl;`
nope that didn't work either.

3. Here's a link to the C++ problem: Sum of Naturals divisible by 3 and 5 | Programr It only has an 11.5% success rate.

Here's another "easy" one with a low success rate (6%).
Sum of Odd Numbers | Programr
Sum all odd numbers less than or equal to a given maximum.
E.g., Given 10 the answer is 25 because 1 + 3 + 5 + 7 + 9 = 25. Given 15 the answer is 64 because 1 + 3 + 5 + 7 + 9 + 11 + 13 + 15 = 64

The code below fails.
Code:
```#include <iostream>
#include <string>
using namespace std;

int main(int argc, char* argv[])
{
long max = 0;               //GIVEN
long sum = 0;               //GIVEN
cout<<"Enter Maximum No:";  //GIVEN
cin>>max;                   //GIVEN
for(long i=1;i<=max;i+=2)
sum += i;
cout<<"Sum of Odd no. is:"; //GIVEN
cout<<sum<<endl;
}```
You should report these problems. It's possible it's due to capitalization differences or something idiotic like that.

4. Hmm, shame that seems a bit discouraging I was enjoying the site. I sent some feedback to them and will advise if I hear anything. Thanks for the help, at least their wasn't any obvious issues with my code.

5. Originally Posted by oogabooga
You should report these problems. It's possible it's due to capitalization differences or something idiotic like that.
Okay, no reply from the website but I found the solution to sum of odd numbers + sum of naturals + others. It was very idiotic.
Remove the last line of code that they give you so that you only output the answer. so in oogabooga example. Just remove line 13.

Page 2 of 2 First 12
Popular pages Recent additions