I need some help ...

Have i written this program right? If not, please improve 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(void)
{
    
int i;
int og;
    
cout << "Insert how oft the loop should repeat: ";
cin >> og;

for( i=0 ; og<=5 ; i++)
{
cout << i << " / ";

}
system("pause");

}
Make sure the loop repeats the correct number of times.
The condition should be i < og instead.

In your program, either infinite loop or no loop is performed.
Thank you very much, Nikko YL!

And how can i change the program so that the numbers are not parallel but among themselves in a column?

This is the actual code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
using namespace> std;

int main(void)
{
	int i;
	int og;

	cout << "Geben Sie ein wie oft die Schleife durchlaufen werden soll? ";
	cin >> og;

	for(i = 0; i < og; i++)
	{
		cout << i << " / ";
	}

	system("Pause");
}
Please help me!
And how can i change the program so that the numbers are not parallel but among themselves in a column?
What do you mean by that , can you show what your desired output looks like ?
If you mean you want each number on its own row you can use std::endl.
 
cout << i << endl;
I already have found it in the forum! :-)

Now my source is this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
using namespace std;

int main(void)
{
	int i;
	int og;

	cout << "Geben Sie ein wie oft die Schleife durchlaufen werden soll? ";
	cin >> og;

	for(i = 0; i < og; i++)
	{
		cout << i <<endl;
	}

	system("Pause");
}


My next thing what i want to do is this output:


When i type in for cin 5 that the output don't look like this:
Geben Sie ein wie oft die Schleife durchlaufen werden soll? 5
1
2
3
4
5

It should look like this:
Geben Sie ein wie oft die Schleife durchlaufen werden soll? 5
5
4
3
2
1
0

Yes also ZERO ! :-)


Thank you soooo much ! :-)
reverse the for loop
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
using namespace std;

int main(void)
{
	int i;
	int og;

	cout << "Geben Sie ein wie oft die Schleife durchlaufen werden soll? ";
	cin >> og;

	for(i = og; i >= 0; i--)
	{
		cout << i <<endl;
	}

	system("Pause");
}
Thank you sooooo much !!!! :-))))))))

Topic archived. No new replies allowed.