Hi I'm new here, and I just started learning C++ programming. I've been looking everywhere on the internet to show me how to combine boolean values and switch() to get the test results. The program just goes to default and print out Grade 0. Am I using the bool wrong or switch wrong? Some pointers would be very appreciated, thank you.
//Test 1. Carbon content is below 0.67
//Test 2. Rockwell hardness is no less than 50
//Test 3. Tensile strength is greater than 70,000 psi
//Grade10 = 3 test pass
//Grade9 = Test1 and test2 pass
//Grade8 = Test 1 pass
//Grade7 = none passed
//Grade0 = for all other cases.
int main()
{
cout << "Please input the carbon content: "; cin >> c;
cout << "\nPlease input the Rockwell hardness: "; cin >> R;
cout << "\nPlease input the Tensile strength: "; cin >> T;
// definitions of tests
t1 = c < 0.67;
t2 = R >= 50;
t3 = T >= 70000;
total = t1 += t2 += t3;
switch( total )
{
case 111: cout << "The metal is Grade 10" << endl; break;
case 110: cout << "The metal is Grade 9" << endl; break;
case 100: cout << "The metal is Grade 8" << endl; break;
case 000: cout << "The metal is Grade 7" << endl; break;
default: cout << "The metal is Grade 0" << endl; break;
} // end switch
} //
It finally works, but I don't understand why it works... I used cout to see what the output will look like, but where is that 3 coming from??
int t1(true);
int t2(true);
int t3(true);
.
.
.
// definitions of tests
if(c < 0.67) t1 += 100;
if(R >= 50) t2 += 10;
if(T >= 70000) t3 += 1;
cout << t1 + t2 + t3 << endl;
switch( t1 + t2 + t3 )
{
case 114: cout << "The metal is Grade 10" << endl; break;
case 113: cout << "The metal is Grade 9" << endl; break;
case 103: cout << "The metal is Grade 8" << endl; break;
case 003: cout << "The metal is Grade 7" << endl; break;
default: cout << "The metal is Grade 0" << endl; break;
} // end switch