Checking for odd numbers and problems with multiple files

I have no idea why this code wont work. It doesen't print out anything to the screen and it doesen't ask for any input either.

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

#include "Oddities.hpp"

#include <iostream>

using namespace std;

int main()
{
cout << "Input number of values : ";
    int num;
cin >> num;
    
    int counter = 0;
    int i;
    while (counter < num) {
        cin >> i;
        
        if (i % 2 == 0)
        {
            cout << num <<  " Is even ";
            }
            else {
                cout << num << " is odd ";
            }
        
        counter++;
            }
     
    
            return 0;
    }


Also, another issue i have is that when i create and use a new file to make a program (in Xcode) i'll get the "build failed" error both when running the new program (in the other file) and the old program, even though the old program worked previously.
Last edited on
https://ideone.com/Jhdn09

Works fine (note that I fixed cout << num << " Is even "; and cout << num << " Is odd"; ).
Last edited on
It may not be working for you because you aren't flushing the output. Also, you aren't prompting for the individual values, so it maybe waiting for input without you knowing about it.

Also, use consistent indenting.
#include <iostream>
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
using namespace std;

int
main()
{
    cout << "Input number of values : " << flush;
    int num;
    cin >> num;

    int counter = 0;
    int i;
    while (counter < num) {
	cout << "Enter a value: " << flush;
	cin >> i;

	if (i % 2 == 0) {
	    cout << i << " is even " << endl;
	} else {
	    cout << i << " is odd " << endl;
	}

	counter++;
    }

    return 0;
}
Topic archived. No new replies allowed.