Hi,
I am almost done with C++ and my project is on Resistors. The problem is that when i try to tun the program, line 37 and 34 has an error saying "no match operator". It is the same as line 28 and 31. Then when I make line 34 and 37 a comment it works but, the program acts in a different way. When asked for color for "band A", i typed in a correct color but when it goes to the member function "checker", it says that the inputted color for "band A" is wrong. The checker returns a correct value but i think it just ignores it or gives it a 1.
Please help me correct this project of mine.
Thank you in advance.
Here is part of my program :
class Resistance
{
private:
string Color[4];
int Resistance, Tolerance;
public:
void GetData();
int Checker();
int Option();
};
void Resistance:: GetData()
{
cout << "Please enter a color for band A: ";
cin >> Color[0];
cout << "Please enter a color for band B: ";
cin >> Color[1];
cout << "Please enter a color for band C: ";
cin >> Color[2];
cout << "Please enter a color for band D: ";
cin >> Color[3];
};
int Resistance:: Checker()
{
if (Color[0] == "black" || "gold" || "silver" || !("brown" || "red" || "orange" || "yellow" || "green" || "blue" || "violet" || "gray" || "white") )
return 1;
if (Color[1] == "gold" || "silver" || !("brown" || "red" || "orange" || "black" || "yellow" || "green" || "blue" || "violet" || "gray" || "white") )
return 2;
if (Color[2] == !("black" || "gold" || "silver" || "brown" || "red" || "orange" || "yellow" || "green" || "blue" || "violet" || "gray" || "white") )
return 3;
if (Color[3] == !("black" || "gold" || "silver" || "brown" || "red" || "orange" || "yellow" || "green" || "blue" || "violet" || "gray" || "white") )
return 4;
};
int Resistance:: Option ()
{
int option;
cout << "Please Choose From The Fallowing Option : " << endl;
cout << "\t1 - Convert color of bands to ohms\n\t2 - Convert ohm to color of bands" << endl;
cout << "Enter Option Number : " ;
cin >> option;
return option;
};
int main ()
{
int option, check;
bool restart;
Resistance A;
option = A.Option();
if (option == 1)
{
do
{
A.GetData();
check = A.Checker();
if(check == 1 ){
cout << "Error! Invalid input in Color band A" << endl;
restart = true;
}
if(check == 2 ){
cout << "Error! Invalid input in Color band B" << endl;
restart = true;}
if(check == 3 ){
cout << "Error! Invalid input in Color band C" << endl;
restart = true;}
if(check == 4 ){
cout << "Error! Invalid input in Color band D" << endl;
restart = true;
}
}
while (restart = true);
}