I'm new to C++, and I was doing the exercise found here:
http://www.learncpp.com/cpp-tutorial/32-arithmetic-operators/
I was doing quiz 2 which tells me co create a program that receives an integer from user, and prints true of that integer is even. So I created the following code:
#include "stdafx.h"
#include <iostream>
int getInteger()
{
std::cout << "Insert an integer" << "\n";
int8_t x;
std::cin >> x;
return x;
}
bool isEven(int8_t x)
{
bool b;
b = false;
std::cout << x % 2 << "\n";
if(x%2 == 0)
{
b = true;
}
return b;
}
void printResult(bool b)
{
std::cout << std::boolalpha;
std::cout << b << "\n";
}
int main()
{
int8_t x;
x = getInteger();
bool b;
b = isEven(x);
printResult(b);
return 0;
}
So, here is the problem. Unless I'm missing something, this should work, right? And it does, but only for integers that I input from 0 to 10. For some reason, if I input 10, or 12, it prints false, but it works fine with 2, 4, 6, and 8. Why is this happening?