Printing output in format eg "2:4;5:6"

Mar 3, 2017 at 6:59am
Hello all,

This is my first post. I am stuck with an assignment requesting me to print an output in the format example of which looks like this:

2:4;5:6

i.i the code that I have to do, needs to count the number of twos and fives in a array and output it like the above. The lecturer had barely even covered programming and did not go into this area.

I was trying to use the cout<<2:4;5:6<<endl

Obviously it is wrong, but I have not even the slightest clue on how to do this. Is anyone willing to help here?

Cheers,

Decker
Last edited on Mar 3, 2017 at 7:06am
Mar 3, 2017 at 7:30am
1
2
int two_count = /**/, five_count = /**/
cout << "2:" << two_count << ";5:" << five_count;
Mar 3, 2017 at 8:07am
Okay, I think I finally got it working:

cout << “2:” << "4" << “; 5:” << "6" << endl;

(i.e. I have the line "using namespace std:", so no need for std::cout and std::endl)

Not sure if anyone needs this somewhere, but if it will - that's great.

Cheers,

Decker
Last edited on Mar 3, 2017 at 8:08am
Mar 3, 2017 at 9:25pm

cout << “2:” << "4" << “; 5:” << "6" << endl;

You can just print it as a single string.
 
cout << "2:4;5:6\n";


I thought the number of twos and fives vary and that you had multiple arrays to test, which is why I made the number of twos and fives variables.
Last edited on Mar 3, 2017 at 9:25pm
Topic archived. No new replies allowed.