Aug 7, 2012 at 12:25am UTC
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;
}
Aug 7, 2012 at 12:29am UTC
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.
Aug 7, 2012 at 1:18am UTC
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 Aug 7, 2012 at 1:19am UTC
Aug 7, 2012 at 1:32am UTC
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};
Aug 7, 2012 at 1:40am UTC
Yes, and I got the following error
10 =`myList' undeclared (first use this function)
Aug 7, 2012 at 1:42am UTC
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 Aug 7, 2012 at 1:43am UTC
Aug 7, 2012 at 1:43am UTC
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