Arrays and stored doubles


I am trying to work through this assignment for a class discussion which I am late submitting because I am not well. I have started writting the code but I am sure there are a few things I am missing> I have been going over it for the best part of the week when I have the strength to be at my laptop but it just isnt clicking through the fog in my head. I just typed this in Word and Have not even tried to run it because I know I am missing some of the code I am just not able to figure out what it is.

This is the actual assignment:

Execute the program in C++, and explain how the array is initialized, how it is used in the program, how the nested for loops work, and what the output of the program is.

"Declare a two-dimensional array that contains 10 rows, each of which will store 4 doubles."

#include "stdafx.h"
#include <iostream>
#include <iomanip>
using namespace std;
int main() {

int temp;
int arr_2d[10][4]
Double
// 10 rows, 4 columns
int arr_2d[10][4] = {{1},

{1,2,3,4},{1,2,3,4},{1,2,3,4},{1,2,3,4},{1,2,3,4},
{1,2,3,4},{1,2,3,4},{1,2,3,4},{1,2,3,4},{1,2,3,4};}

int row, col;

for (row = 0; row < 10; ++row) {
cout << endl;
for (col = 0; col < 4; ++col)
cout << setw(3) << arr_2d[row][col];
}
return 0;
}

I hope someone can guide me through this.
Thanks,
Verna
I just typed this in Word and Have not even tried to run it because I know I am missing some of the code I am just not able to figure out what it is.


Instead typing the code in Word, type it in your compiler (whichever you use). It will tell you the errors that you are causing.

Execute the program in C++, and explain how the array is initialized, how it is used in the program, how the nested for loops work, and what the output of the program is.


The answers on how the arrays and the nested for loops work should be in your textbook.

http://www.cplusplus.com/doc/tutorial/arrays/ (Tutorial for Arrays)

http://www.cplusplus.com/doc/tutorial/control/ (Tutorial for loops)

Take a look at it and comeback with specific questions about your assignment.

Below is your code in code tags:

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
#include "stdafx.h"
#include <iostream>
#include <iomanip>
using namespace std;
int main() {

int temp;
int arr_2d[10][4]
Double
// 10 rows, 4 columns
int arr_2d[10][4] = {{1},

{1,2,3,4},{1,2,3,4},{1,2,3,4},{1,2,3,4},{1,2,3,4},
{1,2,3,4},{1,2,3,4},{1,2,3,4},{1,2,3,4},{1,2,3,4};}

int row, col;

for (row = 0; row < 10; ++row) {
cout << endl;
for (col = 0; col < 4; ++col)
cout << setw(3) << arr_2d[row][col];
}
return 0;
} 
Thank you for your quick response I will give it a try and will also check the links you provided to try and get a better understanding of loops and arrays. I am sure there will be some more questions. We are using visual studio for this class and I am very new to both.
Last edited on
Topic archived. No new replies allowed.