Using a loop to print a decimal array

Ok, I've rewritten this program a million different ways and I dont seem to be getting anywhere. I believe this is the proper format for printing an array (going by my textbook) but I'm getting the following errors:
6 expected primary-expression before "double"
6 expected `;' before "double"

Is this even the right format to print an array?

#include <iostream>
using namespace std;

int main()
{
double mylist[] {0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5};

for (int i = 0; i < 10; i++)
{
cout << myList[i] << ' ';
}
system("pause");

return 0;
}
Try adding an = between the array and the values. I believe it's been updated to support that, but your compiler might just be old.
Thank alot, that worked, but now line 10 says that "mylist" is undeclared.
Did line 6 not declare it correctly?

Here is another way I tried to write the same program, but this one doesn't display anything.
Is there a simple error that I seem to be overlooking?


#include <iostream>
using namespace std;

int main()
{
const int ARRAY_SIZE = 10;
double decimals[ARRAY_SIZE];

for (int x = 10; x < ARRAY_SIZE; x++)
{
cout << decimals[x] << endl;
}

system("pause");

return 0;
}
Last edited on
You tried this?
double mylist[] = {0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5};
Yes, and I got the following error
10 =`myList' undeclared (first use this function)
Look at the differences in the lines:
1
2
3
double mylist[] = {0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5};
// ...
cout << myList[i] << ' ';


Specifically the variable name...
Last edited on
Great! Can't believe I overlooked it
I've been going over this code so many times and rewriting it, i missed it.
Thanks alot
Topic archived. No new replies allowed.