I'm having trouble creating columns in a for loop. I'm suppose to create two columns when the user enters 2 for cin. I've created an if statement with a nested for loop.
The output is suppose to be like this:
Number of columns: 2
A B
C D
E F
G H
I J
K L
M N
O
but the way i coded it it turns out to be like this:
Number of columns: 2
A B C D E F G H I J K L M N O
What do i need to do create two columns
here's what i have so far:
#include <iomanip>
#include <iostream>
using namespace std;
int main()
{
int column, ctr, column_ctr;
char ch;
while (ctr=1)
{
cout << "Number of column: ";
cin >> column;
cout << endl;
if (column==0)
{return 0;}
else if (column==1)
{for (ch='A'; ch<='O'; ch++)
{cout << setw (9) << ch << endl;}
cout << endl;
}
else if (column==2)
{for (ch='A'; ch<='O'; ch++)
{cout << setw (9) << ch;}
cout << endl << endl;
}
ctr++;
}
return 0;
}
This post has been edited by Martyn.Rae: 22 March 2010 - 10:04 AM
Reason for edit:: Edited end code tag

New Topic/Question
Reply
MultiQuote









|