Five sets of 3 double numbers stored in a 5x3 array in C++,
How do i do this, I have this so far
include <iostream>
# include <iomanip>
# include <cstring>
# include <cstdlib>
using namespace std;
int main ()
{
const int NUMROWS = 5;
const int NUMCOLS = 3;
int i, j;
int val [NUMROWS] [NUMCOLS] = {num};
cout << "\nDisplay using nested for loop: " << endl;
for (i = 0; i < NUMROWS; i++)
{
cout << endl;
for (j = 0; j < NUMCOLS; j++)
cout << setw(4) << val[j];
}
cout << endl;
return 0;
}

Recommended Answers

All 3 Replies

You're doing good!

Just to let you know:
Please use [code]

[/code] tags. It makes source code way easier to read.

I'm assuming you just missed a charecter when you copied the code to the clipboard:

include<iostream>

Should be:

#include <iostream>

You need to put a space between "using" and "namespace":

usingnamespace std;

And lastly, you'll need to fill in numbers for the array:

int val [NUMROWS] [NUMCOLS] = {num};

Usually how numbers are inputted into an array when a variable is intitalized is like this:

= { {num, num, num}, {num, num, num} /* etc. */};

All the rest of the code is good.

Hope this helps

Here's the code. You dont really need the last two #includes in the program.. Not sure if you needed them for later though..

#include<iostream>
#include<iomanip>

using namespace std;

int main ()
{
    const int NUMROWS = 5;
    const int NUMCOLS = 3;
    int i, j, num = 0;
    int val [NUMROWS] [NUMCOLS] = {{num,num,num},{num,num,num},{num,num,num}};

    cout << "\nDisplay using nested for loop: " << endl;

    for (i = 0; i < NUMROWS; i++)
    {
        cout << endl;
        for (j = 0; j < NUMCOLS; j++)
            cout << setw(4) << val[i][j];
    }
    cout << endl;
return 0;
}

Sorry, you need the {num,num,num} 5 times here, not 3:

int val [NUMROWS][NUMCOLS] = {{num,num,num},{num,num,num},{num,num,num},{num,num,num},{num,num,num}};
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.