Print a line with * depending on integer from user

I have to write a program that prints * depending on the user input. The user inputs 5 integers and outputs the corresponding *'s. So 1=* 3=*** 5=*****, etc.


Here's what I got so far: Any hints or tips or can someone help me fix it? I'm not sure how to ensure the user inputs 5 times.

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
using namespace std;

int main()
{
    int input = 0;
    

    cout << "Enter an integer: ";
    cin >> input;
    
    for (int x=0; x< iput, x=++}
}


Last edited on
Try this,

1
2
3
4
for(int x=0; x<input; x++)
{
       cout<<"*";
}
How can I make it continually loop? Do I need a control condition/while loop?
or
is it possible to have the user input 5 integers in the beginning and have the output show at the end?


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

int main()
{
    int input = 0;

    cout << "Enter an integer: ";
    cin >> input;
    
    for(int num=0; num < input; num++)
{
       cout<<"*";
}
	   
}
Yes, just get the input into 5 different integers, then do 5 for loops, one for each integer.
Either or. Personally I would do the while loop option so you don't end up hard coding it ie you can have n amount of integers.
Topic archived. No new replies allowed.