The RentCar function isn't working properly, I want it to compare binary 1's and 0's to switch the default 0 value of the first bit to a value of 1 but it seems to output
0 0 0
When it should be outputting
0 1 0
It seems to work fine if I set variables such as
unsigned char Car0 = 1;
etc, but it doesn't seem to like Enums...
#include <iostream>
using namespace std;
enum CARS { Car0 = 1, Car1 = 2, Car2 = 4, Car3 = 8, Car4 = 16, Car5 = 32, Car6 = 64, Car7 = 128 };
void RentCar(unsigned char f, CARS c) {
f = f | c;
}
void ReturnCar(unsigned char f, CARS c) {
f = f ^ c;
}
bool RentalStatus(unsigned char f, CARS c) {
if ((f & c) == c) {
return true;
}
else {
return false;
}
}
//void showFleet() {
// int car = 0;
// while (car < 8) {
// cout << "Car" << car << ": ";
// if (fleet & car) {
//
// }
// }
//}
int main() {
unsigned char fleet = 0; // 1 byte, 1 bit per car status
cout << (int) fleet << endl;
RentCar(fleet, Car0);
cout << (int) fleet << endl;
cout << RentalStatus(fleet, Car0);
}