在if条件中使用multiple和or语句

时间:2018-06-01 18:58:28

标签: if-statement conditional

#include <iostream>
using namespace std;


main()
{
  char a[2];



  cout << "         \"Welcome to Virtual University\" " << endl;
  cout << "     Program to predict user programming level" << endl;

  cout << " Please answer in either T=True or F=False" << endl;

  cout << "Q:1 Switch is a loop?" << endl;
  cout << "A:  ";
  cin >> a[0];

cout << "Q:2 Pointer stores memory address?" << endl;
cout << "A:  ";
cin >> a[1];

cout << "Q:3 Semicolon after for loop is an error? " << endl;
cout << "A:  ";
cin >> a[2];



if((a[0] == 'f') || (a[0] == 'F') && (a[1] == 't') || (a[1] == 'T') && (a[2] 
== 'f') || (a[2] == 'F')) 
    {
        cout << "Your programming level is advanced" << endl;
    }
 else if((a[0] == 'f') || (a[0] == 'F') && (a[1] == 't' ) || (a[1] == 'T') 
&& (a[2]== 't') || (a[2] == 'T')) 
    {
        cout << "Your programming level is intermediate" << endl;
    }
else if((a[0] != 'f') || (a[0] != 't') && (a[1] != 't' ) || (a[1] != 'f') && 
(a[2] != 't') || (a[2] != 'f')) 
    {
        cout << "please enter t or f only" << endl;
    }
else
    {
        cout << "Your programing level is begginner" << endl;
    }
    return 0;



}

它没有在编译器中给出任何错误,但是当我运行这个``程序时,它总是打印错误的语句。你能不能帮帮我吧 当我删除||有资本F和T的条件。工作正常。 任何人都可以帮助那些大写字母,因为它是我的任务中的要求。提前谢谢。

0 个答案:

没有答案