Member Avatar for kohkohkoh

here is the question:

Use a two-dimensional array called price to hold the prices for Proton’s car
regarding to the models and CC as listed below.

--------------------------------------------------------------------------

in 2d array..i could get
(for example)

void disp(a[][3]);

int main()
{
num[3][2] = { {1,2},{4,5},{7,8} }
disp(num);
return 0;
}

void disp(a[][3])
{
for (int i=1; i<=3 ; i++)
for (int i=1; i<=2 ; i++)

cout << a[j] << endl;
}

--------------------------------------------------------------------------
my question is:
how do i seperate the i and j so i could form like a table..
something like this:

model price
i j
i+1 j+1
i+2 j+2
.....and so on..

instead of
1 2
4 5
7 8

All i want is to spread i and j wide....

p.s Get what i mean??

Something like this?

#include <iostream>

void disp(int a[][[color=Red]2[/color]])
{
   for ( int i = [color=Red]0[/color]; i [color=Red]< [color=black]3[/color][/color] ; i++ )
   [color=Red]{[/color]
      for ( int j = [color=Red]0[/color]; j [color=Red]< [color=black]2[/color][/color] ; j++ )
      {
         std::cout << a[i][j] [color=Red]<< ' ';[/color]
      }
      [color=Red]std::cout << std::endl;[/color]
   [color=Red]}[/color]
}

int main()
{
   int num[[color=black]3[/color]][[color=black]2[/color]] = { {1,2},{4,5},{7,8} };
   disp(num);
   return 0;
}

/* my output
1 2 
4 5 
7 8 
*/
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.