Outputting 2d arrays..please help

I am just a student in a class which the teacher is learning the language with us so I need desperate help. I am using microsoft visual c/c++ 5.0 and this is my program currently.


#include

#include

#include

int main()

{

int count[4][5];

int x, y;

for (x=0;x<=3;++x)<br>
{

for (y=0;y<=4;++y)<br>
{

cout<<"Please enter the ammount of drug number "<<y+1<<" for store number "<<x+1<<endl;<br>
cin>>count[y][x];

}

system ("CLS");

}

x=0;

y=0;

for (x=0;x=3;++x)

{

cout<<"Store: 1"<<setw(15)<<"Store: 2"<<setw(15)<<"Store: 3"<<setw(15)<<"Store: 4"<<setw(15)<<"Store: 5"<<endl;<br>
for (y=0;y=4;++y)

{

cout<<setw(5)<<count[y][x]<<endl;<br>
}

}

system ("CLS");

return 0;

}



The assignment was to output a table which asks for the ammount of 4 different drugs for 5 different stores. I can get them to be loaded into the array but I don't know on how to output them correctly. You do not need to give me the exact answer but please do help me.


Xaviar


Comments

  • I did a copy and paste onto this bored and I noticed that after it is posted some things didn't go up and it wasn't in the correct spacing...sorry if you are going to help me please excuse those problems. My actual program does have correct spacing etc etc


    Xaviar

    : I am just a student in a class which the teacher is learning the language with us so I need desperate help. I am using microsoft visual c/c++ 5.0 and this is my program currently.


    : #include

    : #include

    : #include

    : int main()

    : {

    : int count[4][5];

    : int x, y;

    : for (x=0;x<=3;++x)<br>
    : {

    : for (y=0;y<=4;++y)<br>
    : {

    : cout<<"Please enter the ammount of drug number "<<y+1<<" for store number "<<x+1<<endl;<br>
    : cin>>count[y][x];

    : }

    : system ("CLS");

    : }

    : x=0;

    : y=0;

    : for (x=0;x=3;++x)

    : {

    : cout<<"Store: 1"<<setw(15)<<"Store: 2"<<setw(15)<<"Store: 3"<<setw(15)<<"Store: 4"<<setw(15)<<"Store: 5"<<endl;<br>
    : for (y=0;y=4;++y)

    : {

    : cout<<setw(5)<<count[y][x]<<endl;<br>
    : }

    : }

    : system ("CLS");

    : return 0;

    : }

    :

    : The assignment was to output a table which asks for the ammount of 4 different drugs for 5 different stores. I can get them to be loaded into the array but I don't know on how to output them correctly. You do not need to give me the exact answer but please do help me.


    : Xaviar





  • You output 2d arrays the same way that you input 2d arrays. One element at a time, probably on the inside of two loops.


    For the following array:


    int x[10][20];


    The following loop will output each integer:


    int i,j;


    for (j=0;j<10;++j)<br>
    for (i=0;i<20;++i)<br>
    cout << x[j][i] << ' ';<p>


    Alternatively, you may wish it to be in grid format... which means that you'll have to output an end-of-line (the endl manipulator) after each iteration of the outer loop.


    This is only one way to do it of course, and you'll have to spend some time getting the spacing right (using the setw manipulator, the left and right manipulators, or the iostream flags, whatever).


    Since you seem to have gotten some of this in the program you posted, I'm wondering precisely what problem you have and what you really want.




Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories