/*
inputs an integer N, followed by a sequence of N positive integers and outputs a sequence, where each odd integer from the input is multiplied by 2, and each even integer is replaced by 0. The values of the input integers are within a range from 1 to 99, and N is less than 100.
*/
You'll need to store the integers the user gives you in an array or a std::vector. Since there are no more than 100 inputs, you can just use an array of 100 elements.
Once you have the inputs, transform them: evens to zero, odds times two.
Are you really going to suggest a way to subvert his teacher's instruction?
What use is it to get the list back at the same time you give it? Unless you are a batch process, and most humans aren't, the jumble of information is hard enough to read as to make it nearly useless, and sure to get him a bad grade.
Of course. The necessary info is stored in one element, not in the entire sequence, and there is no gain using an array (in fact you are wasting memory).
The "teacher" is not explicit to use arrays. And if your students comes with a better solution (or just a different that it is not crap) why are you going to punish them?
Besides, it looks more like a batch process
Edit: To know if a number is even you could use the modulo operator %
The "teacher" is not explicit to use arrays. And if your students comes with a better solution (or just a different that it is not crap) why are you going to punish them?
Now this is a topic that touches the nerves of some teachers. As teachers, some feel they are to teach their students and *NOT* the students to teach them back. If that is the case, the teacher may feel slight-ed their students can be "better than them" isn't it ?
There are another group of teachers that subscribe to another school of thoughts. To them as teacher not only are they there to teach, but they are also there to learn from their students too. This mean they do accept students that can come out with innovative solutions where in this scenario both parties learn from each other isn't it ?
I personally subscribe to the second school of thoughts. When I teach, I expect to learn too. I don't want to just teach without learning new stuff myself. This is my character.
I believe Scott Meyers learn from his students too and later the production of Effective C++ is a great success. It is truly a very informative book that comprises of ideas and solutions from teacher and students.
I also am a teacher. I don't feel slighted when someone turns in innovative thinking.
However, I do feel obligated to insist that the students work with the material we are covering in class.
I realize that the problem can be done without arrays. Unfortunately for that train of thought, the problem has earmarks of being a manufactured, arrays homework problem. Personally I don't like the way the assignment is presented, however, I cannot take the OP's presentation as the teacher's presentation. I can only use what I know about methods typically used in beginning CS courses and extrapolate from that. (My conclusion could be wrong.)
Intelligence and creative thinking by the student is always welcome. However, especially for a beginning CS course, it is expected that the students use the methods and structures currently being covered in class, instead of figuring out ways to not use it.