Program to make rows of digits, never going into double digits

I have this so far
//File: digits.cpp
//Created by: Brett Malinowski
//Created on: 9/24/2012

/*
A program to print out the number
of rows which the user inputs,
never having a double digit value
*/

#include <iostream>

using namespace std;

int main()
{
//Define variables
int n; // Number of rows
int i; // Row count in for loop
int k; // Output for loop

// Have user input n
cout << "Enter number of rows: ";
cin >> n;

// Complete for loop
for (i = 1; i <= n; i++)
{
for (k = 1; k < i%10; k++)
{
cout << k;
}
cout << endl;
}

return 0;
}


But it should output like this if the input is 11
1
12
123
1234
12345
123456
1234567
12345678
123456789
1234567890
12345678901

but its doing this
1
12
123
1234
12345
123456
1234567
12345678
123456789

1


I know it has something to do with the modulus (%) function, but I need help understanding what to do.
Thank you.
Your logic is messed up.

1
2
3
4
5
6
7
8
for (i = 1; i <= n + 1; i++)
{
  for (k = 1; k < i; k++)
  {
    cout << k%10;
  }
  cout << endl;
}
Topic archived. No new replies allowed.