write a programme to capture 3 numbers and determine the smallest and the largest.

Do you mean something like this:

#include <iostream>

using namespace std;

int min (const int a, const int b);
int max (const int a, const int b);

int main()
{
    int a, b, c;

    cout << "Enter three numbers: " << endl;
    cin >> a >> b >> c;

    cout << "Lowest: "  << min(min(a,b), c) << endl
         << "Highest: " << max(max(a,b), c) << endl;

    return 0;
}

int min (const int a, const int b)
{
    return (a < b) ? a : b;
}

int max (const int a, const int b)
{
    return (a > b) ? a : b;
}

Or is there some sort of catch?

@Gonbe - Do you think it would be better for someone trying to learn to get an informed nudge or suggestion rather than a working solution? Often times a full solution only serves to further bury a person struggling with the basics.

@Gonbe - Do you think it would be better for someone trying to learn to get an informed nudge or suggestion rather than a working solution? Often times a full solution only serves to further bury a person struggling with the basics.

Potentially. In this case I was confused with the actual question as the solution is very trivial and hardly "nudgeable". The problem would be:

1) No idea how to read 3 numbers. => very easy to google
2) No idea how to determine the highest/lowest. => It's very easy to develop an algorithm that does it as you'd do it on paper. The only issue I could imagine here would be not knowing how to translate that into code which boils down to not knowing how boolean operators/branching work. (assuming math libraries may not be used. Function knowledge might help as well but not needed)

So yeah, in this case I posted the/a solution as the question is, as mentioned, trivial and I wouldn't be able to nudge him towards anything he wouldn't easily be able to find himself.

The problem is he wasnt wasnt able to easily get there himself thats why he asked. The person either didnt want to do it or didn't know how so by you giving them the answer it does them nothing but get them further behind in their lessons.

it does them nothing but get them further behind in their lessons.

If he mindlessly copy pastes it without even trying to understand what's going on I have no guilty conscience about that. People should be intelligent enough to make the best of a given answer.

But yeah, had this discussion in the 'C' section before and I don't plan on repeating it. Downvote me for it or get my post removed by an admin/moderator if it upsets you. You have my permission.

The person either didnt want to do it

I'd argue that if he didn't want to write such a simple program he's at a level where Gonbe's code would be easily recognizable as plagiarized by any teacher with more than two brain cells to rub together. That's assuming he's both lazy and unscrupulous enough to turn in the program as if he wrote it.

Our primary concern when it comes to homework solutions is cheating. We don't want to be blacklisted, which has happened before (hint hint, Gonbe, it's not just an arbitrary guideline). Solutions that are conceptually helpful by solving the problem or a similar problem, but practically unhelpful because they're too advanced to be turned in directly are generally acceptable because it makes cheating difficult.

or didn't know how so by you giving them the answer it does them nothing but get them further behind in their lessons.

Let's consider two of the most likely situations where the student is unwilling to take an example and learn from it:

  1. He's in a programming class: In this situation, he would have failed in short order regardless, so getting further behind isn't the catastrophe that your statement makes it out to be.

  2. He's teaching himself: Nobody is hurt in this situation except him, and if he's unwilling to do any work with provided examples and working code to really understand them, failure in the venture was guaranteed before it even started.

If you fell posting a solution that is too advanced for them to turn in then I'm fine with that. I'd just hate to see something I wrote getting turned in and people asking me why I gave someone a complete program for a homework problem.

+1 Gonbe and deceptikon.

People do learn by going through, reasoning about, and then understanding a solution to a problem. Someone learning programming is not all that much different from a child learning to speak - the child learns by listening to people speak correctly.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.