Help with multiples of 3?

Hi everyone. Ive had some trouble with this weeks practice assignment. Basically, we are supposed to write a function that will print a char symbol '*', for everything BUT the multiples of 3, e.g 3, 6, 9 12,. Formatted to look like this;

**3* (notice it continues counting every char, instead of restarting at each
*3** new row, how do i do this?)
3**3

I cant for the life of me figure out how to do this, every piece of code ive tried in my function yields inadequate results.
Here is what i have so far, any tips would be appreciated. Thanks

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
 #include <iostream>
using namespace std;

void print(int rows, int cols, char charUsed);

int main() 
{


	print(3, 4, '*');
	cin.get();
	return 0;
	
}

void print(int rows, int cols, char charUsed) 
{
	for (int r = 1; r <= rows; r++) 
	{
		for (int c = 1; c <= cols; c++) 
		{
			if (c % 3 == 0) cout << "3"; // this is what wont work
			else cout << charUsed;
		}
		cout << endl;
	}
}
You just need a variable to hold current value and not reset it on each loop iteration
1
2
3
4
5
6
7
8
9
10
11
void print(int rows, int cols, char charUsed) 
{
    int i = 1; //<--
    for (int r = 0; r < rows; ++r) { //Canonical form
        for (int c = 0; c < cols; ++c) { 
            if (i++ % 3 == 0) cout << "3"; //Works now
            else cout << charUsed;
        }
        cout << endl;
    }
}
I have a question about the the output. Is it only going to print 3 rows and 4 columns? Or do you have plans of repeating this program. What I mean is the output going to start to have a pattern, like:
**3*
*3**
3**3
**3*
*3**
3**3
@MiiNiPaa Thanks Alot! That really helps. it makes sense that in order to have continuity for the numbers on each row i would need to create a counter, instead of taking the values of the table itself.

@Anthony5347 The assignment does not specify the dimensions necessary. So its really up to our own judgement. My guess though is that our code needs to be able to function correctly if the dimensions are changed, which is accomplished by creating the counter, as in MiiNiPaa's example.
Topic archived. No new replies allowed.