为什么我得到了正确的输出,但它也显示程序 2 和 3 的 if else 输出

Why do I get the right output but it also displays the if else output for program 2 and 3

这是一个入学项目,每个项目都有一定的条件

//The front
cout<<"Welcome to admission system"<<"\n";
cout<<"---------------------------"<<"\n";
cout<<"Admission open for year 2022"<<"\n";
cout<<"Press 1 for BSc Electrical Engineering Department"<<"\n";
cout<<"Press 2 for BSc Mechanical Engineering Department"<<"\n";
cout<<"Press 3 for MSc Mechanical Engineering Department"<<"\n";

//Personal details
cout<<"Your personal details"<<"\n";
cout<<"---------------------"<<"\n";
cout<<"Enter your Civil ID:";
cin>>civil_no;
cout<<"Enter your Name: ";
cin>>name;
cout<<"Enter Age: "<<"\n";
cin>>age;
cout<<"Enter contact Number: ";
cin>>phone;
cout<<"Enter program applying for: ";
cin>>pg; //pg here is meant as the department the user want to choose 

//Education details
cout<<"Education Details"<<"\n";
cout<<"-----------------"<<"\n";
cout<<"Enter Applicant highest qualification passing years:";
//cin>>year_of_passing;
cout<<"Enter Qualification Passing Year:";
//cin>>qualification;
cout<<"Enter Obtained marks (%):";
//cin>>marks;


//Program 1
if (pg==1 && marks>=60 && qualification==12) {
    cout<<"You are fully eligible for this program1"<<"\n";
}
else if(pg==1 || marks<60 || qualification!=12){
    cout<<"you are not eligible 1"<<"\n";
}


//Program 2
if (pg==2 && marks>=65 && qualification==12) {
    cout<<"You are fully eligible for this program 2"<<"\n";
}
else if(pg==2 || marks<65 || qualification!=12){
    cout<<"you are not eligible 2"<<"\n";
}


//Program 3
if (pg==3 && marks>=70 && qualification==14) {
    cout<<"You are fully eligible 3"<<"\n";
}
else if(pg==3 || marks<70 || qualification!=14){
    cout<<"you are not eligible 3"<<"\n";
}

无论pg==1还是2还是3,总能进入另外两个程序的else条件。 例如, 假设:pg == 1 and marks= 62 and qualification = 12,

1.如果块

它将进入程序1
//Program 1
if (pg==1 && marks>=60 && qualification==12) {
    cout<<"You are fully eligible for this program1"<<"\n";
}

2。会进入程序2的else块

else if(pg==2 || marks<65 || qualification!=12){
    cout<<"you are not eligible 2"<<"\n";
}

3。会进入程序3的else块

else if(pg==3 || marks<70 || qualification!=14){
    cout<<"you are not eligible 3"<<"\n";
}

这是因为在 else 块中,您使用了 或 || 条件,因此即使有一个条件(在本例中为标记)出现事实证明,该块将执行!

if else 语句组不正确。例如,如果您输入的限定值不等于 12,则将执行所有三个 else 语句,因为条件 qualification!=12 在所有三个 else 语句中的计算结果为真。

你需要写任何一个

//Program 1
if (pg==1 && marks>=60 && qualification==12) {
    cout<<"You are fully eligible for this program1"<<"\n";
}
else if(pg==1 && ( marks<60 || qualification!=12 )){
    cout<<"you are not eligible 1"<<"\n";
}


//Program 2
if (pg==2 && marks>=65 && qualification==12) {
    cout<<"You are fully eligible for this program 2"<<"\n";
}
else if( pg==2 && ( marks<65 || qualification!=12 )){
    cout<<"you are not eligible 2"<<"\n";
}


//Program 3
if (pg==3 && marks>=70 && qualification==14) {
    cout<<"You are fully eligible 3"<<"\n";
}
else if( pg==3 && ( marks<70 || qualification!=14 ) ){
    cout<<"you are not eligible 3"<<"\n";
}

或者例如

//Program 1
if ( pg==1 )
{ 
    if ( marks>=60 && qualification==12) {
        cout<<"You are fully eligible for this program1"<<"\n";
    }
    else {
        cout<<"you are not eligible 1"<<"\n";
    }
}


//Program 2
if (pg==2 )
{
    if ( marks>=65 && qualification==12) {
        cout<<"You are fully eligible for this program 2"<<"\n";
    }
    else {
        cout<<"you are not eligible 2"<<"\n";
    }
}


//Program 3
if ( pg==3 )
{
    if ( marks>=70 && qualification==14) {
        cout<<"You are fully eligible 3"<<"\n";
    }
    else {
        cout<<"you are not eligible 3"<<"\n";
    }
}