Mistery

Hi everyone. I have 5 tasks to do at home. I've been trying to do the first one, but it's not going very well.
The assignments are actually short and easy, but I study medicine, and I think I'm far too stupid to do any programming, so if anyone could help me please :/

So here's the first assignment for example:

Write a code where you enter 10 integers into an "array".
After that, make a "list" of the type you choose, and fill that list with values from the array.
When you finish that, make a function DELETE_EVENS where you will send your list, and in that function delete all even numbers (0 is not an even number).
A function should return the "corrected" list, with only numbers that are odd.
Before and after the function gets called, the content of the list should be printed out.

I've come this far, working for the last 8 hours... I don't know how to "send" a list into the function, because I get several errors always :/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <cstdlib>
#include <iostream>
#include <list>

using namespace std;

int list<int> DELETE_EVENS(int ){
    
}

int main(){
    
    int a[10], i, *pa;
    pa = &a[0];
    
    for (i = 0; i < 4; i++){
        printf("Enter %d. number\n", i+1);
        scanf("%d", pa + i);
    }
    
    list<int> myList(10,0);
    list<int> tempList (pa, pa + sizeof(pa) / sizeof(int) );//only copies the first element ?!?!!
    
    for (list<int>::iterator it = pa.begin(); it != pa.end(); it++) {
         showDebugMsg("value is: ", *it); //Prints out zero, the first element. (After initializing each element with a size of one?
    }
        
    for(i = 0; i < 4; i++){
          //printf("%d\n", *pa + i);
          printf("%d\n", pa[i]);
    }
    
    system("PAUSE");
    return 0;
}
On line 22, the size of pa is the size of a pointer to int. It is not the size of the array it points to. A pointer may point to an array of any size, or a single object.

Line 24 will result in a compilation error. pa is not a container object and does not have methods begin or end.
I'm reading your comment for the 5. time, I don't understand almost anything. Could you please explain a bit easier?
Topic archived. No new replies allowed.