Confused Again [sorry]

Again looking through the guide, it told me to type this-


#include <iostream>
using namespace std ;


int main()
{
// Declared then initialized.
float nums[3] ;
nums[0] = 1.5 ; nums[1] = 2.75 ; nums[2] = 3.25 ;

// Declared and initialized.
char name[5] = { 'm', 'i', 'k', 'e', '\0' } ;
int coords[2] [3] = { { 1, 2, 3 } , { 4, 5, 6 } } ;
}

And then include this-

cout << "nums[0]: " << nums[0] << endl ;
cout << "nums[1]: " << nums[1] << endl ;
cout << "nums[2]: " << nums[2] << endl ;
cout << "name[0]: " << name[0] << endl ;
cout << "string: " << name << endl ;
cout << "coords[0][2]: " << coords[0][2] << endl ;
cout << "coords[1][2]: " << coords[1][2] << endl ;
return 0 ;

}


From my last thread I put together the entire code so it looks like this now:

#include <iostream>
using namespace std ;


int main()
{
// Declared then initialized.
float nums[3] ;
nums[0] = 1.5 ; nums[1] = 2.75 ; nums[2] = 3.25 ;

// Declared and initialized.
char name[5] = { 'm', 'i', 'k', 'e', '\0' } ;
int coords[2] [3] = { { 1, 2, 3 } , { 4, 5, 6 } } ;
}
cout << "nums[0]: " << nums[0] << endl ;
cout << "nums[1]: " << nums[1] << endl ;
cout << "nums[2]: " << nums[2] << endl ;
cout << "name[0]: " << name[0] << endl ;
cout << "string: " << name << endl ;
cout << "coords[0][2]: " << coords[0][2] << endl ;
cout << "coords[1][2]: " << coords[1][2] << endl ;
return 0 ;

}

Now I dont know what I did wrong, but when I tried compiling it into a .exe file the command prompt said:
C:\My Programs>c++ arrays.cpp -o arrays.exe
arrays.cpp:15: error: expected constructor, destructor, or type conversion befor
e '<<' token
arrays.cpp:16: error: expected constructor, destructor, or type conversion befor
e '<<' token
arrays.cpp:17: error: expected constructor, destructor, or type conversion befor
e '<<' token
arrays.cpp:18: error: expected constructor, destructor, or type conversion befor
e '<<' token
arrays.cpp:19: error: expected constructor, destructor, or type conversion befor
e '<<' token
arrays.cpp:20: error: expected constructor, destructor, or type conversion befor
e '<<' token
arrays.cpp:21: error: expected constructor, destructor, or type conversion befor
e '<<' token
arrays.cpp:22: error: expected unqualified-id before "return"
arrays.cpp:24: error: expected declaration before '}' token


If you understand this, please reply.
*Page 19 of C++ Programming in easy steps by Mike Mcgrath.*
You have an extra closing brace:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
using namespace std ;


int main()
{
// Declared then initialized.
float nums[3] ;
nums[0] = 1.5 ; nums[1] = 2.75 ; nums[2] = 3.25 ;

// Declared and initialized.
char name[5] = { 'm', 'i', 'k', 'e', '\0' } ;
int coords[2] [3] = { { 1, 2, 3 } , { 4, 5, 6 } } ;
}   // This shouldn't be here
cout << "nums[0]: " << nums[0] << endl ;
cout << "nums[1]: " << nums[1] << endl ;
cout << "nums[2]: " << nums[2] << endl ;
cout << "name[0]: " << name[0] << endl ;
cout << "string: " << name << endl ;
cout << "coords[0][2]: " << coords[0][2] << endl ;
cout << "coords[1][2]: " << coords[1][2] << endl ;
return 0 ;

}


And please use [code][/code] tags when posting code
Ok, I replaced the code, it is now:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
using namespace std ;


int main()
{
// Declared then initialized.
float nums[3] ;
nums[0] = 1.5 ; nums[1] = 2.75 ; nums[2] = 3.25 ;

// Declared and initialized.
char name[5] = { 'm', 'i', 'k', 'e', '\0' } ;
int coords[2] [3] = { { 1, 2, 3 } , { 4, 5, 6 } } ;
}   // This shouldn't be here
cout << "nums[0]: " << nums[0] << endl ;
cout << "nums[1]: " << nums[1] << endl ;
cout << "nums[2]: " << nums[2] << endl ;
cout << "name[0]: " << name[0] << endl ;
cout << "string: " << name << endl ;
cout << "coords[0][2]: " << coords[0][2] << endl ;
cout << "coords[1][2]: " << coords[1][2] << endl ;
return 0 ;

}


And when I typed in the "c++ arrays.cpp o- arrays.exe" this came up.

1
2
3
c++: o-: No such file or directory
c++: arrays.exe: No such file or directory
arrays.cpp:24:2: warning: no newline at end of file
I'm pretty sure it's '-o' not 'o-'
@Rikazu
Did you read the code or you just copied and pasted?
Check line 14
Topic archived. No new replies allowed.