Newbie need help!

Hello all, i started studing basic c++ programing in sweden, and are atm at a final test for the course.

Im supose to build a program that will creat a "pattern" resulting from what number u enter. like following exampel.
--


Enter a number (Quit with "0"): 3

*
**
***

Enter a number (Quit with "0"): 5
*
**
***
****
*****

and so on.

Atm i can get the program to show.

122333444455555

or

1
2
2
3
3
3
4
4
4
4
.

My current code looks like this

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include<iostream>
#include<conio.h>
using namespace std; 
int main( )
{
    int Nummer=1;
    while(Nummer!= 0)
   {
        cout<<"Enter a number (Quit with "0"):";
        cin>>Nummer;
       if ( Nummer!= 0)
		   for(int reps = 1; reps<=Nummer;reps++)
		   for(int Nummer = 1; Nummer<=reps;Nummer++)
			   cout<<reps<<" "<<endl;
		   cout<<endl;
    }
    cout<<"program quit! ";
    getch();
    return 0;
}


Im still very unfamiluar with c++ and getting this result as taken me prolly about shamely 10-11 hours.

Any help would be apretiated.
A confused c++ user
/Resk
Last edited on
Remember that '\n' and endl indicate the end of the line. See now if you can get it to print:

1
22
333
4444

then instead of printing the number, just print a '*'.

Hope this helps.
Yeah i know, thou i still only manage to print either

1223334444

or

1
2
2
3
3
3

Could it be that im using a wrong kind of code?
Maybe a bit sloppy, but try 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
#include <iostream>
using namespace std; 

int main () {
		int num=666;
while (num != 0){
    cout << "Enter a number (Quit with '0'): ";
	cin >> num;
	int nu=0;
	int nl=0;

	while (nu < num){
	nu++;

    nl=0;
		while (nl < nu){

	cout << "*";
	nl++;
	}
	cout << "\n";
	}
	}
    return 0;
	
}
Cheers for the replys!

awesomealpha, that was exacly what i was looking for!
Thou i managed to somehow write one myself

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include<iostream>
#include<conio.h>
using namespace std; 
int main( )
{
    int num,reps;
    while(num!= 0)
   {
        cout<<"Ange ett tal, vill du avsluta ange 0 :";
        cin>>num;
       if ( num!= 0)
		   for(int reps = 1; reps<=num;reps++){
			   cout<<"";
		   for(int num = 1; num<=reps;num++)
			   cout<<"*"<<"";
		   cout<<endl;
		   }
	}
	cout<<"program slut! ";
	getch();
    return 0;
}


Yours look cleaner thou.
Thank you once again for the fast replys.
/Resk
Topic archived. No new replies allowed.