FOR Loop 2 variables, printing ascending/descending order

Use two variables inside the parantheses of a for() loop. Write a program with minimal lines that outputs two columns of integers. The first column prints integers in ascending order, the second column prints integers in descending order

I currently have the following:

---------------------------------------------------------------------------
//printout one column from 1to 5, and the next columm
//from 5 to 1


#include <iostream>

using namespace std;

int main()
{
int upNum = 1;
int dwNum = 5;

for ( upNum <= 5, dwNum >= 1; upNum > 5, dwNum < 1; upNum++, dwNum-- )
{
cout << "\t" << upNum << "\t" << dwNum << endl;
}


cout << "\n\n\n\n\t\t\t";

system ("pause");
return 0;
}

---------------------------------------------------------------------------


Nothing comes out as an output
Last edited on
In the line for ( upNum <= 5, dwNum >= 1; upNum > 5, dwNum < 1; upNum++, dwNum-- ), you can see that you have written upNum <= 5, dwNum >= 1; upNum > 5, dwNum < 1. upNum can't be <= 5 and > 5 at the same time, and dwNum can't be >= 1 and <1 at the same time.

In a for loop, the first is where you declare your variables - for(upNum = 1, dwNum = 5), the second is where you set your condition - < 5, > 5, etc and the third is where you do what you need to do (++, --).

Also, please use [c0de][/c0de] tags in the future, as opposed to using bold.
1
2
3
4
5
6
#include <iostream>
int main(){
    for (int upNum = 1, dwNum = 5; upNum <= 5, dwNum >= 1; ++upNum, --dwNum)
        std::cout << '\t' << upNum << '\t' << dwNum << '\n';
    return 0;
}

Try this.
Hi,

Thanks so much...I spent about an hour and now its done...I appreciate...
Topic archived. No new replies allowed.