Prining a * from a user input integer Loop Help
How can I make it continually loop? It only asks for it one time? Is it possible to stop it after 5 times? 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?
Code:
#include <iostream>
using namespace std;
int main()
{
int input = 0;
cout << "Enter an integer: ";
cin >> input;
for(int num=0; num < input; num++)
{
cout<<"*";
}
}
Re: Prining a * from a user input integer Loop Help
Am I understanding correctly that you wish to execute the cout/cin pair as well as the following for loop multiple times?
Simple wrap another for loop around whatever you want to repeat.
Re: Prining a * from a user input integer Loop Help
Quote:
Originally Posted by
ashley19
How can I make it continually loop? It only asks for it one time? Is it possible to stop it after
5 times? 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?
Code:
#include <iostream>
#include <vector>
using namespace std;
int main()
{
std::vector<int> inputs;
for(int i = 0; i < 5; ++i)
{
cout << "Enter an integer: ";
cin >> inputs[i];
}
for(int i = 0; i < 5; ++i)
{
cout<< inputs[i];
}
}
Like that?
Re: Prining a * from a user input integer Loop Help
That isn't entirely correct.
Re: Prining a * from a user input integer Loop Help
I added a while loop, with counter. But I'm not sure why it's an infinite loop. can someone modify this so I can learn what I'm doing wrong? I only want this loop to run 5 times.
Code:
#include <iostream>
using namespace std;
int main()
{
int input = 0;
int counter = 0;
cout << "Enter an integer (between 1-30): ";
cin >> input;
while(counter != 5)
{
for(int num=0; num < input; num++)
{
cout<<"*";
}
}
}
Re: Prining a * from a user input integer Loop Help
Well, you never modify counter within the loop (or anywhere else). Of course it's going to be infinite.
Re: Prining a * from a user input integer Loop Help
got it thanks!!!
<3Lindley
Re: Prining a * from a user input integer Loop Help
got it thanks!!!
<3Lindley
Re: Prining a * from a user input integer Loop Help
Quote:
Originally Posted by
Lindley
That isn't entirely correct.
Care to elaborate or just going to leave it at that?