Christos
  • Christos
d) Ask the user to enter values only at the items with an EVEN position.
Computer Science
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
jamiebookeater
  • jamiebookeater
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
Christos
  • Christos
Where is my mistake? #include using namespace std; int num[15]; int u=0; int main() { for(int i=0; i<15; i++) { num[i]= i + 1; if (num[i]%2 == 0) { cin >> num[i]; cout << num[i]; cout << " "; } else { cout << num[i]; cout << " "; } } return 0; }
Christos
  • Christos
ignore the int u=0 it's just an unused variable.
anonymous
  • anonymous
What exactly are you trying to do here? you are using the mod operator to decide if there is a remainder after dividing by 2 So you are looking for only numbers that can be divided without a remainder?

Looking for something else?

Not the answer you are looking for? Search for more explanations.

More answers

anonymous
  • anonymous
What does even items mean? are you speaking of positions in the array?
anonymous
  • anonymous
try to comment out this line //num[i]= i + 1;
anonymous
  • anonymous
your for loop increments and your cin moves the user input into the array.
anonymous
  • anonymous
The problem is in the body of your if statement if (num[i]%2 == 0)
anonymous
  • anonymous
here is the correct code #include using namespace std; int num[15]; int main() { for (int i=0; i < 15; i++) { if (i % 2 == 0) { cin >> num[i]; cout << num[i] << endl; } } return 0; } put a break point on the cout line to check the results
anonymous
  • anonymous
The way you had it you were checking the value inside the array rather then the index of the array.
anonymous
  • anonymous
really you don't need the cout statement at all according to the question. since the question is only asking for input.

Looking for something else?

Not the answer you are looking for? Search for more explanations.