Display ASCII chars spreadsheet - Any thoughts?

Yes, this is a homework assignment, however once again I am just trying to spruce it up some with the x values being displayed (not required for the homework). It would be better if I could get the y values to display as well but I can't seem to get that to happen. I have tried putting in several different for iterations as well as if/else only to not get what I was looking for. Any help would be appreciated. Again, by taking out the x values being displayed I will get full credit, so I have the assignment done. Thanks in advance.

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
#include <iostream>
#include <cmath>
#include <cstring>
#include <iomanip>

using namespace std;

int main()
{
	cout << endl << "ASCII Spreadsheet " << endl << endl;

	int x, y;
	
	for (x = 40; x < 120; x += 10)
	{
		cout << setw(4) << x;

	    for (y = 0; y < 10; y++)
	    {
		
		cout << setw(4) << char(x+y); 	    
	}

	    cout << endl;
	}
	return 0;

}


The following is the output:



ASCII Spreadsheet 

  40   (   )   *   +   ,   -   .   /   0   1
  50   2   3   4   5   6   7   8   9   :   ;
  60   <   =   >   ?   @   A   B   C   D   E
  70   F   G   H   I   J   K   L   M   N   O
  80   P   Q   R   S   T   U   V   W   X   Y
  90   Z   [   \   ]   ^   _   `   a   b   c
 100   d   e   f   g   h   i   j   k   l   m
 110   n   o   p   q   r   s   t   u   v   w

Hint: they should be printed in a loop you should insert between lines 12 and 14.
Hmmm... that sort of worked. The code is now:

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
#include <iostream>
#include <cmath>
#include <cstring>
#include <iomanip>

using namespace std;

int main()
{
	cout << endl << "ASCII Spreadsheet " << endl << endl;

	int x, y;

	for (y = 0; y < 10; y++)
	{
	cout << setw(4) << y << "\t";
	cout << endl;
	}	

	for (x = 40; x < 120; x += 10)
	{
		cout << setw(4) << x;

	    for (y = 0; y < 10; y++)
	    {
		
		cout << setw(4) << char(x+y); 	    
	}

	    cout << endl;
	}
	return 0;

}


However the output was as follows:


ASCII Spreadsheet 

   0	
   1	
   2	
   3	
   4	
   5	
   6	
   7	
   8	
   9	
  40   (   )   *   +   ,   -   .   /   0   1
  50   2   3   4   5   6   7   8   9   :   ;
  60   <   =   >   ?   @   A   B   C   D   E
  70   F   G   H   I   J   K   L   M   N   O
  80   P   Q   R   S   T   U   V   W   X   Y
  90   Z   [   \   ]   ^   _   `   a   b   c
 100   d   e   f   g   h   i   j   k   l   m
 110   n   o   p   q   r   s   t   u   v   w


Obviously I have missed a step. I tried variations of where to put a tab in, trying to get them all on the same line (even white space cout << " ";) but the end result is typically identical to what is shown above.
Did you try not printing a newline after each iteration?
That worked and has gotten me on the right track. Thanks. Being a beginner at this stuff, sometimes it makes me laugh how a simple error like that can change everything. Thanks again for the help.
Topic archived. No new replies allowed.