what are you having trouble with on #1?
The biggest thing I need help with on is how to print out 10 elements per line
its just an array with 50 elements printed out in 10's
10 elements per line need to be outputted. But, How do I do that?
I thought maybe a nested for loop like this one
for (index = 0; index < 50; index++)
for (item = 0; item < 10; item++)
cout << alpha[index] << " " << endl;
But, is that how?
Probably nothing like that, right?
I doubt myself.
There ya go. But the first loop should not be increased by 1, but 10, otherwise you'll have 40 more sets of 10 printing out then expected
Not quite. What you want is more like:
for (i = 0; i < 5; i++)
{
for (j = 0; j < 10; j++)
{
cout << alpha[10*i + j] << " ";
}
cout << endl;
}
Here's what I did (Doesn't work properly tho)
#include
#include
using namespace std;
int main(int argc, char *argv[])
{
double alpha[50];
int index;
for (index = 0; index < 25; index++)
alpha[index] = index^2;
if (index == 10)
cout << alpha[index] << endl;
else if
(index == 20)
cout << alpha[index] << endl;
else cout << alpha[index] << " ";
for(index = 25; index < 50; index++)
alpha[index] = index * 3;
if (index == 30)
cout << alpha[index] << endl;
else if
(index == 40)
cout << alpha[index] << endl;
else if
(index == 50)
cout << alpha[index] << endl;
else cout << alpha[index] << " ";
system("PAUSE");
return EXIT_SUCCESS;
}
First of all ^ does not do what you think it does, its an exclusive or logical operator, not power, you want to include cmath and use pow for that.
Second, I'd be amazed if you could even tell me in english what that code does. Any good compiler would complain that index at lines x y and z will never be 10, 20, 30, 40, or 50, a clue right there that your printing is notpart of your looping calculation.
First, do your calculations which looks like you want to square the index and store it into the first 25 elements, then multiples of 3 on the index for the remaining 25 (two seperate loops)
THEN, do your print out code, which we already gave you tips on in other comments