-
October 13th, 2009, 04:53 PM
#1
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<<"*";
}
}
-
October 13th, 2009, 05:52 PM
#2
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.
-
October 13th, 2009, 05:53 PM
#3
Re: Prining a * from a user input integer Loop Help
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?
-
October 13th, 2009, 06:22 PM
#4
Re: Prining a * from a user input integer Loop Help
That isn't entirely correct.
-
October 13th, 2009, 11:00 PM
#5
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<<"*";
}
}
}
-
October 13th, 2009, 11:11 PM
#6
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.
-
October 13th, 2009, 11:18 PM
#7
Re: Prining a * from a user input integer Loop Help
got it thanks!!!
<3Lindley
Last edited by ashley19; October 14th, 2009 at 12:09 AM.
-
October 14th, 2009, 12:09 AM
#8
Re: Prining a * from a user input integer Loop Help
got it thanks!!!
<3Lindley
-
October 14th, 2009, 04:23 AM
#9
Re: Prining a * from a user input integer Loop Help
Originally Posted by Lindley
That isn't entirely correct.
Care to elaborate or just going to leave it at that?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|