Basic C++ assignment guidance needed.

Hello. I'm new to C++ and I need to create a program like this:

You first ask for a number, let's say I input 6 and this is what I should get

******
*****
****
***
**
*

basically it inputs as many stars as the number you gave and substracts 1 and keeps going until it reaches 0.

It's simple but I can't figure out how to use loops correctly in order to do it -_-'

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

int main() {

int number;

cout << "Enter an integer > " << flush;
int >> number;







cin.get();
cin.get();
return 0;
}
Last edited on
Your program doesn't compile.
 
int >> number;
'
You use "cin" for input - cin >> number;

You can start by using char to assign the value '*'

char star = '*';

You can create a while-loop that runs as long as "number" doesn't equal 0. And inside it a for-loop that prints out number amount of stars. Then after doing that, you subtract 1 from "number", so that next time it prints out 1 less, Until it reaches 0.

Hope this helps a bit =)
Dude, I had the thing completed and I accidentally removed it, I ran some programs to get it back but didn't work. I'm 100% this is how the code was but it's not working, what am I missing!?? Seriously pissed off now.

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

#include <iostream>
using namespace std;

int main() {


int annettu;
int i;

cout << "Anna kokonaisluku > " << flush;
cin >> annettu;


	
  	while (i < annettu) {
	
		for(i=0;i<annettu;i++) {
	
		
		cout << "*" << flush;
		
	}
		
cout << endl;
annettu = annettu - 1;
 }

		
		
	
		


cin.get();
cin.get();
return 0;
}
while (i < annettu) Should be: while (0 < annettu)// note the 0

Last edited on
Thank you, so damn much <3
Last edited on
My pleasure^^
Topic archived. No new replies allowed.