Quantcast
Channel: CodeGuru Forums - Visual C++ Programming
Viewing all articles
Browse latest Browse all 3029

please help me correct this code

$
0
0
I made this code
Code:

#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
Code:

#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 :)

Viewing all articles
Browse latest Browse all 3029

Latest Images

Trending Articles



Latest Images