blood type compatibility
#include<iostream>
#include<string>
bool Bool_type(const std::string& Recipient,const std::string& Donor);
int main(){
std::cout<<"Please enter the blood type of the recipient:\t ";
std::string Recipient;
std::cin>>Recipient;
std::cout<<"Please enter the blood type of the donor:\t ";
std::string Donor;
std::cin>>Donor;
int R{0};
int D {0};
for(const char& c:Recipient)R+=c;
for(const char& c:Donor)D+=c;
if(R!=110&&R!=108&&R!=109&&R!=111&&R!=174&&R!=176&&R!=122&&R!=124){
std::cerr<<"Invalid input"<<std::endl;
return 0;
}
if(D!=110&&D!=108&&D!=109&&D!=111&&D!=174&&D!=176&&D!=122&&D!=124){
std::cerr<<"Invalid input"<<std::endl;
return 0;
}else{
std::cout<<std::boolalpha<<Bool_type(Recipient,Donor);
}
std::cout<<std::endl;
return 0;
}
bool Bool_type(const std::string& Recipient,const std::string& Donor){
if(Recipient == "A+"){
if(Donor == "A+"|| Donor =="A-" || Donor == "O+" || Donor == "O-"){return true;}
}else if(Recipient =="A-"){
if(Donor == "A-" || Donor == "O-"){return true;}
}else if(Recipient == "B+"){
if(Donor =="B+"||Donor == "B-"|| Donor == "O-" || Donor == "O+"){return true;}
}else if(Recipient == "B-"){
if (Donor == "B-"|| Donor == "O-") {return true;}
}else if(Recipient == "AB+"){
if(Donor=="A+"||Donor =="A-"||Donor=="B+"||Donor== "B-"||Donor=="AB+"||Donor=="AB-"||Donor=="O+"||Donor == "O-"){return true;}
}else if(Recipient == "AB-"){
if(Donor=="AB-"||Donor=="A-"||Donor=="B-"||Donor=="O-"){return true;}
}else if(Recipient=="O+"){
if(Donor=="O+"||Donor=="O-"){return true;}
}else if(Recipient == "O-"){
if(Donor=="O-"){return true;}
}
return false;
}