-
looping practice
before you lauph i did this because im a noob and i didnt know if i could do this.
basically i want it so the program runs asks you wut number you want to loop and then does it but i got an error.
Code:
#include <iostream>
using namespace std;
int main()
{
int numb;
cout<<"please input the number you would like to loop\n";
cin>>numb;
//for the next part where it says <10 i dont really know wut this is but i dont want it.
for ( int x = int numb; x <10; x++ ) {
cout<< x <<endl;
}
cin.get();
}
-
I think you wnat this:
Code:
#include <iostream>
using namespace std;
int main()
{
int numb;
cout<<"please input the number you would like to loop\n";
cin>>numb;
//for the next part where it says <10 i dont really know wut this is but i dont want it.
for ( int x = 0; x <numb; x++ )
{
cout<< x <<endl;
}
cin.get();
-
Sorry Loctan, was making my reply while you posted yours.
That code is quite buggy (you are new, some this is understandable). Allow me to show you what is wrong.
Code:
for (int x = int numb; x < 10; x++) {
You want to loop up to the value that the user entered, correct? If so, what you want is.
Code:
for (int x = 0; x < numb; x++) {
Now, you want your "cout <<x << endl;" within braces (within the for loop). In the end do:
Code:
#include <iostream>
using namespace std;
int main()
{
int numb;
cout << "Please input the number you would like to loop\n";
cin >> numb;
for (int x = 0; x < numb; x++)
{
cout << x << endl;
}
cin.get();
return 0; //This is not necessary, but good common practice.
}
-
thank you but now how do i keep the screen up
never mind i figure out i should use cin.ignore but another problem arises when i say goto 21 itll go to 20
-
you shouldn't use goto while loops are much more effective
-
Then you would want this
Code:
for (int x = 0; x <= numb; x++)