Thread: need help with task

  1. #16
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,314
    Quote Originally Posted by Afik
    why it say that in length of digits the number is 4900, and not both in sum and in length is 7963
    That's because both 4900 and 7963 are 4 digit numbers. 4900 came first, so it holds the distinction of being the number with the max length. Therefore, the output is correct.

    You can of course have more complicated "tiebreaker" requirements, e.g., if there is more than one number with the max length, pick the number that also has the max digit sum, but then you're going to have to change your implementation to handle this, e.g., store all the current known numbers with max length in an array, and all the current known numbers with max digit sum in another array, then compute the intersection of the two arrays. So, it can be done, but I'd suggest checking the requirements with your teacher first.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  2. #17
    Registered User
    Join Date
    Sep 2020
    Posts
    7
    Quote Originally Posted by laserlight View Post
    That's because both 4900 and 7963 are 4 digit numbers. 4900 came first, so it holds the distinction of being the number with the max length. Therefore, the output is correct.

    You can of course have more complicated "tiebreaker" requirements, e.g., if there is more than one number with the max length, pick the number that also has the max digit sum, but then you're going to have to change your implementation to handle this, e.g., store all the current known numbers with max length in an array, and all the current known numbers with max digit sum in another array, then compute the intersection of the two arrays. So, it can be done, but I'd suggest checking the requirements with your teacher first.

    ok, how I do this? can you help me? I want to do more complicated "tiebreaker".....

  3. #18
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,314
    Firstly, are you sure you need to do this? Ask your teacher to be sure. It is good practice, but introducing complexity increases the chance of a bug. I'm guessing you're not using version control, so at the very least you should save a copy of your current working code to submit in case you mess this up.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help me with the task please :3
    By flakee in forum C Programming
    Replies: 3
    Last Post: 03-28-2016, 08:20 AM
  2. Help from the task
    By MAJA83 in forum C Programming
    Replies: 1
    Last Post: 06-06-2012, 11:35 AM
  3. Need help to do the big task
    By Steve Cao in forum Linux Programming
    Replies: 1
    Last Post: 07-16-2010, 02:01 PM
  4. Replies: 2
    Last Post: 12-31-2007, 11:40 AM
  5. Task Bar
    By cfrost in forum Windows Programming
    Replies: 1
    Last Post: 07-22-2004, 07:37 AM

Tags for this Thread