Christos
  • Christos
Why this code can't print on a straight line ? C++
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.
chestercat
  • chestercat
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
anonymous
  • anonymous
what code?
Christos
  • Christos
#include using namespace std; int num[15]; int u=0; int main() { for(int i=0; i<15; i++) { num[i]= i; if (num[i]%2 == 0) { cin >> num[i]; cout << num[i]; cout << " "; } else { cout << num[i]; cout << " "; } } return 0; }
anonymous
  • anonymous
I already answered this question.

Looking for something else?

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

More answers

Christos
  • Christos
I tried the new code but it doesn't seem to pring odd number sequence correctly , if you try it you will see
anonymous
  • anonymous
but the question said to only allow the array to except values in it's even positions.
anonymous
  • anonymous
your instructor will most likely set a break point on the cin line to see if it work correctly.
Christos
  • Christos
The exersise says to "ask the user to enter values only at even positions" which is like saying " odd positions should be a default sequence from 1 to 15 (picking only the odds) since the first part of the exersise is this a) Declare an array called “Num” with 15 integers.
Christos
  • Christos
Another example which I solved: c) Change all the items of the array with an ODD position to -1
Christos
  • Christos
But the even positions stay intact regardless
anonymous
  • anonymous
#include using namespace std; int num[15]; int main() { for (int i=0; i < 15; i++) { //this line checks the index of the array //because i is used as the index if (i % 2 == 0) { cin >> num[i]; cout << num[i] << endl; } } return 0; } This works I have checked the code myself
anonymous
  • anonymous
for the odd part you would just check for numbers with remainders then assign -1 to the spots with the remainders num[i] = -1;
anonymous
  • anonymous
Also all code can be put on a straight line as long as the syntax is correct.
anonymous
  • anonymous
a compiler ignores blank space during the scanning process.
anonymous
  • anonymous
Although it would be highly irrational to put all code on one line.
e.mccormick
  • e.mccormick
If you put ``` above and below a code block, it does code high lighing and allows it to be copied properly. There are also code pasting services, like http://dpaste.com These two things can make it easier for people to help you.

Looking for something else?

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