Loop only printing string once (converted from char and with character inserts)

I want the numbers 1-7 to be printed 4 times (4 weeks), and have made
code which replaces input specified numbers with a letter.
I have written the 1-7 as char for ease to select index for character replacement, but am printing it as a string so I can insert spaces after the replacements are done.

Note: I have also made a function there which will mean the user input can be day number since week one day one, and it will still replace the appropriate day. That is what the ADD function is.

For some reason though the string will only print once .
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
28
  #include <iostream>

using namespace std;

char calander0[4][8] {'1', '2', '3', '4', '5', '6', '7', '\0'};

void add(int a) {int b = a - 1; int c = b-7; int d = b-14; int e = b-21; if (a <= 7){calander0[0][b] = 'R';} else if (a >= 8 && a <= 14){calander0[1][c] = 'R';} else if (a >= 15 && a <= 21){calander0[2][d] = 'R';} else if (a >= 22 && a <= 28){calander0[3][e] = 'R';}}

void print(int j) {
	int i = j;
	string calander = calander0[i]; 
	for (int n = 1; n <= calander.length(); n++) {
	 calander.insert(n++, " ");
	}
	cout << calander;
	cout << "Are you looping?"; //It is.
}
int main() {
	int in;
    cout << "Enter date:\n";
    cin >> in;
    add(in);
    for (int h = 0; h <= 3; h++) {print(h);};

    int no_throw;
    cin >> no_throw;
}


SOLVED with:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void print(int j) {
	int i = j;
	string calander = calander0[i]; 
	for (int n = 1; n <= calander.length(); n++) {
	 calander.insert(n++, " ");
	}
	cout << calander;
	int c = 1;
	c++;
	if (c==2) {cout << calander;}
	c++;
	if (c==3) {cout << calander;}
	c++;
	if (c==4) {cout << calander;}
}


I suppose there was something about the calander string that meant it would only return once. Surely must have been because of converting from char, and that not working with it also being a varying initialisation.
Last edited on
Topic archived. No new replies allowed.