I want to know how the unsigned integer works.
#include <iostream>
using namespace std;
int main(){
int a = 50; //basic integer data type
unsigned int b; //unsigned means the variable only holds positive values
cout << "How many hours do you work? ";
cin >> b;
cout << "Your wage is " << b << " pesos.";
}
But when I enter -5, the output is
Your wage is 4294967291 pesos.
And when I enter -1, the output is
Your wage is 4294967295 pesos.
Supposedly, unsigned integers hold positive values. How does this happen? And I only know basic C++. I don't understand bits.