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. #16
    Registered User
    Join Date
    Jul 2012
    Posts
    12
    Quote Originally Posted by ZuK View Post
    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. #17
    Registered User
    Join Date
    Jul 2012
    Posts
    12
    Quote Originally Posted by oogabooga View Post
    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. #18
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    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.
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

  4. #19
    Registered User
    Join Date
    Jul 2012
    Posts
    12
    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. #20
    Registered User
    Join Date
    Jul 2012
    Posts
    12
    Quote Originally Posted by oogabooga View Post
    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 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. NtSetSystemTime() failed
    By medp7060 in forum C++ Programming
    Replies: 11
    Last Post: 04-02-2010, 02:58 AM
  2. execv failed :(
    By Andaluz in forum Linux Programming
    Replies: 6
    Last Post: 09-25-2009, 01:41 AM
  3. GetPrivateProfileString failed
    By vart in forum Windows Programming
    Replies: 3
    Last Post: 02-24-2008, 12:19 PM
  4. i tried myself for 2 hours but failed.
    By epidemic in forum C++ Programming
    Replies: 0
    Last Post: 04-02-2007, 05:46 PM
  5. Assertion Failed!
    By magic.mike in forum Windows Programming
    Replies: 3
    Last Post: 02-14-2005, 02:04 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21