How to limit output responses?

Hi all! I am hoping I can ask this in a general way and avoid a lot of details. I am tasked with writing a code that will output given responses based on certain user inputs. For example: user inputs a number < 15 and a string < hello, and this generates a response of “dude”. There are about 10 or so different constraints like the one in the previous sentence, but a few of these overlap causing 3 or 4 responses to output. My code must at most show 2 responses. Is there a way to limit the output responses to 2? Thanks!

Not the most elegant, but you can write a function that outputs your messages. Have that function count the number of messages. If the count is greater than 2, then suppress the message.

1
2
3
4
5
6
void output_message (const string & msg, int & count)
{   if (count >= 2)
        return;
    cout << msg << endl;
    count++;           
}

Last edited on
It looks plenty elegant to me, much appreciated. I knew there was a way to “count”, but I’m just still too new at this to use that feature efficiently. I’ll give it a whirl…thanks!
Topic archived. No new replies allowed.