Can't seem to get this program to work

Hi, I'm new to C++. I'm having an issue with an assignment given to me. The purpose of this program is to calculate the sum of numbers from 1 to the users input, which must be in the range of 1 to 19 and odd. I have to issues. First, the program won't show the error message for an incorrect entry of the numbers
2, 6, 10, 14, and 18; but correctly does for the other even numbers. 2nd issue: I can't seem to get the sum function to work correctly. I'm very new to this so any assistance would be greatly appreciated :)

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
36
37
38
39
40
41
42
43
  #include <iostream>
using namespace std;


int odd_check(int& num)
{
        bool correct_num;

        do
        {
                cout << "Please enter an ODD number in the range of 1 - 19: ";
                cin >> num;
                cout << endl;

                if ((!((num <= 19) && (num >= 1))) || ((num % 2) == 0))
                {
                        cout << "INVALID CHOICE! " << endl;
                }
                else
                {
                        correct_num = num;
                        return correct_num;
                }
        }
        while ((!((num >= 1) && (num <= 19))) || ((num & 2) == 0));
}

int sum_func(int& num)
{
        int sum = 0;
        int count;
        for (count = 1; count <= num; count++);
                sum += count;
                return sum;
}
int main()
{
        int num;
        odd_check(num);
        cout << "You entered " << num << endl;
        cout << "Sum is " << sum_func(num) << endl;
        return 0;
}
I find your if statement to be extremely confusing
I've cleaned it up


// Check if within 1 to 19 and check if odd
if((num <= 19 && num >= 1) || num % 2 == 1)
// Success
else
// Error
Topic archived. No new replies allowed.