Nov 4, 2014 at 6:59pm Nov 4, 2014 at 6:59pm UTC
I made this code
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 41 42 43
#include <iostream>
#include <iomanip>
using namespace std;
const int ro=5;
const int col=5;
void multi(int mb[ro][col])
{
for (int i = 1; i < ro; i++) {
mb[0][i] = i;
}
for (int i = 1; i < ro; i++){
mb[i][0] = i;
for (int j = 1; j < col; j++)
mb[i][j] = i * j;
}
}
int main()
{
int mb[ro][col] ={};
multi(mb);
for (int i = 0; i < ro; i++) {
for (int j = 0; j < col; j++) {
cout << " " << setw(4) << mb[i][j];
}
cout << endl;
}
system("pause" );
return 0;
}
it outputs a 5x5 multiplication table...the thing is the professor wants us to use global variables for the array as well
so i think the code would look something like this
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 41 42 43
#include <iostream>
#include <iomanip>
using namespace std;
const int ro=5;
const int col=5;
int mb[ro][col];
void multi()
{
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 5; j++){
mb[ro][col]= i * j;
}
}
}
int main()
{
multi();
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 5; j++) {
cout << " " << setw(4) << mb[ro][col];
}
cout << endl;
}
system("pause" );
return 0;
}
the thing is i only get 16's :D I know I'm missing something but i can't see it .thanks :)
Last edited on Nov 4, 2014 at 7:00pm Nov 4, 2014 at 7:00pm UTC
Nov 4, 2014 at 7:15pm Nov 4, 2014 at 7:15pm UTC
mb[ro][col];//line 35 change ro and col to i and j
Nov 4, 2014 at 7:22pm Nov 4, 2014 at 7:22pm UTC
i changed ro and col as suggested but i only get 0's D:
Nov 4, 2014 at 7:26pm Nov 4, 2014 at 7:26pm UTC
Ooh sorry i forgot change line 15 too to the same
Nov 4, 2014 at 7:28pm Nov 4, 2014 at 7:28pm UTC
w00t m8 thanks for the help you made a man happy today :D