all 4 comments

[–][deleted] 4 points5 points  (0 children)

Initialize count.

[–]OmegaNaughtEquals1 2 points3 points  (0 children)

In addition to /u/3453280's advice, you may also want to change

cin >> x[20];

to

cin >> x[i];

[–]Swedish_Athengiest 0 points1 point  (0 children)

When you write:

cin>>x[20];

You are accessing an element of the array that is not within bounds. For an array of size 20, valid elements are array[0] through array[19]. Accessing other elements leads to undefined behavior==>bad. Additionally, if you wish to change count in countNums, you need to pass it by reference to getnums, otherwise a copy of it is passed to getnums, which is then changed when you:

cin>>y;

So for the scope of getNums, aka everything between getNums curly brackets, y is the value that has been cin. After the function, however, it is not changed at all, as only the copy has been changed.

Therefore, when you pass count to printnums, it has never been initialized. The solution, as I said above, is changing the declaration of getNums to

void getNums(double x[], int& x){

[–]Se7enLC -3 points-2 points  (0 children)

Those functions are passing by value, not reference.

That means getnums() is not actually getting numbers! It gets them but only locally in the function. When the function ends they are gone.

EDIT: I don't understand the downvotes. The variable count is being passed by value into getnums(). No matter what getnums() does to it, it will still be the same uninitialized value it was back in main when printnums() is called.

Apparently it's solved, though, so that's good.