I've figured it out now.
My program works correctly, I was just not understanding why in the loop it outputs the right numbers instead of what j is during the loop. For example: in the program the loop that shows A is:
1 2 3 4 5 6 7 8 9 10 11
|
//Shows A
cout << "A = " << endl;
for (int i = 0; i < 2; ++i)
{
for (int j = 0; j < 3; ++j)
{
cout << multiA[i][j] << " ";
}
space
}
space
|
It outputs:
I was wondering why it didn't show what j was assigned instead which would be 0, 1, 2.
Now I realize i and j isn't just for the loop but part of the array kind of, so during the first iteration of both loops it's the same as:
Not sure while I didn't understand that earlier, I feel stupid now....
There is also another program, I couldn't figure it out but now I'm more confused after looking at the answer than I was before. The program is:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
#include <iostream>
#include <string>
using namespace std;
int main()
{
unsigned char myChar;
int count = 0;
for (int i = 33; i <= 255; ++i)
{
if (count % 10 == 0)
{
cout << endl;
}
myChar = i;
cout << i << ": " << myChar << " ";
++count;
}
system("Pause");
}
|
I have no idea how this ends up showing ASCII symbols. Especially because:
1 2
|
myChar = i;
cout << i << ": " << myChar << " ";
|
During that part it assigns i to myChar and then during the output statement i outputs the number it is currently at and myChar shows an ASCII. Instead of the ASCII why doesn't it output the number that i outputted because: