how to keep track of how many characters are output

my program is supposed to only output 10 characters per line and i got that but i also need it to keep track of how many were output so the next input i give it, it only puts that remainder on the next line.

output should look like this

Please enter a positive integer: 7
Please enter a character: =
=======Please enter a positive integer: 9
Please enter a character: +
+++
++++++

my program is like this
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <iostream>

using namespace std;

int main() 

{
  
  int integer;
  char character;

 while (integer >0)
{cout << endl;

  cout << endl;
  cout << "Please enter a positive integer ";
  cin >> integer;
 if (integer > 0)
{ cout << "Please enter any character";
  cin>> character;


cout << endl;
cout << endl;


        cout << "The positive integer you entered is " << integer << endl;
        cout << "The character you entered is " << character << endl;


    for (int N = 1; N <=integer; N++)
    {
        
        std::cout << character;
        if (N % 10 == 0) 
            std::cout << endl;
           
    }
cout << endl;
}      
                      else cout << "That is not valid integer!!!";
    cout << endl;
}
  return 0;
}


just wondering if someone has any suggestions how i can get this to happen
Last edited on
I'm not sure about cout but printf() returns the amount of characters printed. Or you could have a loop and cout 1 character at a time...

http://www.cplusplus.com/reference/clibrary/cstdio/printf/
cout is the same as printf(), im not sure where to put the loop in is the problem when i put it in different places my output gets really messed up
closed account (iw0XoG1T)
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
#include <iostream>
#include <vector>
using namespace std;
int main(){
	int integer=0;
	int hold_number=0;
	char character=0;
	vector<char>out;
	while(true){
		cout<<"enter integer: ";
		cin>>integer;
		if(integer==0) break;

		cout<<"enter character: ";
		cin>>character;

		for(int i=0; i<integer;++i)out.push_back(character);
		while(out.size()-hold_number>10){
			for(int i=hold_number; i<hold_number+10;++i)cout<<out[i];
			hold_number=hold_number+10;
			cout<<endl;
		}
		integer=0;
	}
	return 0;
}
Last edited on
thanks that helps a bit i will work with that to see if i can get it
Topic archived. No new replies allowed.