Question about loops and columns

I am very new to C++ with only a few months experience. I have encountered a problem that is becoming challenging for me to fix.
I have been given an assignment to print out the ASCII code number and character values 33-126 in a chart that has 3 columns using for loops.
My problem is making the second for loop work in sync with the first, without the for loop repeating itself continuously.

Will someone take a look at my current code and help me solve my problem?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//Assignment:
             /*print out the ASCCI code number and character values 33-126 in a chart that has 3 columns*/

#include <iostream.h>
#include <iomanip.h>

int main ()
{
int y,x;
//Variables
y=32;
x=63;

//Chart name
cout<<setw(45)<<"ASCII CHARACTER CODES"<<endl;
    
    //Border
    for (int i=1 ; i<=68 ; i++)
    cout<<"*";
    cout<<endl;
//Column headings   
cout<<"*"<<setw(8)<<"Code"<<setw(4)<<"|"<<setw(6)<<"Char"<<setw(5)<<"+"<<setw(7)<<"Code"<<setw(4)<<"|"<<setw(7)<<"Char"<<setw(4)<<"+"<<setw(7)<<"Code"<<setw(4)<<"|"<<setw(7)<<"Char"<<setw(4)<<"*"<<endl;
    
    //Border
    for (int i=1 ; i<=68 ; i++)
    cout<<"*";
    cout<<endl;
    
    //For ASCII values (33-64) Column 1
    for (int i=33 ; i<=64 ; i++ )
   
   {
        for (int j=65 ; j<=96 ; j++ )
        //ASCII Chart Output
        cout<<"*"<<setw(8)<<i<<setw(4)<<"|"<<setw(6)<<char(y+=1)<<setw(5)<<"+"<<setw(7)<<j<<endl;
   }
system("PAUSE");
return 0;
}
Last edited on
Code tags and indentation required.
I'm still confused as to what you mean.
Read this then: http://www.cplusplus.com/articles/firedraco1/
Somebody tell me if the "how to ask" tells people to use damn code tags. I didn't find it in a quick skim just now but I wasn't looking very hard.
lol it says that in the top one XD
What? I searched "tag" in the read before posting and how to ask threads and I got nothing... where'd you find it?
Thanks for the link.
I just put in the code tag.
Always Anonymous wrote:
My problem is making the second for loop work in sync with the first, without the for loop repeating itself continuously.
That's the thing with console programming using the standard library. You always have to output line by line. I would just combine them into a single for loop that prints each line. You would need to add a constant to get the correct number on the next columns.
Topic archived. No new replies allowed.