Arrays and Indices
For my next to last for loop, I'm trying to get the odd indices to print 1 and even indices to print 0. I'm having trouble trying to print the even indices. #include<iostream> #include <cstdlib> #include<ctime> using namespace std; int main() { int myArray[10]; //print 0 for ea. element for (int a = 0; a < 10; a++) { myArray[a] = 0; cout << "Element" << a << "= " << myArray[a] << endl; } //print random # for ea. element srand(time(0)); for (int a = 0; a < 10; a++) { myArray[a] = rand() % 10 + 1; cout << "Random" << a << "= " << myArray[a] << endl; } //print odd # for ea. element for (int a = 0; a < 10; a++) { myArray[a] = 2 * a + 1; cout << "Term" << a << "= " << myArray[a] << endl; } //print odd elements=1 and even elements=0 for (int a = 0; a < 10; a++) { int evenArr = 0; int oddArr = 1; myArray[a] = a++; if (myArray[a] % 2 == 0) cout << "Even" << a << "= " << evenArr << endl; else cout << "Odd" << a << "= " << oddArr << endl; } //print elements to multiples of 10 then print backwards for (int a = 0; a < 10; a++) { myArray[a] = 10 + 10 * a; } for (int a = 9; a >= 0; a--) { cout << "Multiple" << a << "= " << myArray[a] << endl; } system("pause"); return(0); }