I'm trying to make student information output while studying c++.
int main()
{
int Stu[2][20] = { {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20},
{21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40} };
char Name[20] = { 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T' };
int Num;
int Low = 1;
int High = 20;
int Mid = 0;
cout << "Enter the student's school number :";
cin >> Num;
for (int i = 0; i < 5; i++)
{
Mid = (Low + High) / 2;
if (Num = Stu[0][Mid])
{
Cout << "School Registration" << "<< Stu[0][Mid]<" The name of the student is "<< Name[Mid] <<" and the number is "<<<Stu[1]<"< "Number <<<<"
break;
}
else if (Num > Stu[0][Mid])
{
Low = Mid;
}
else
{
High = Mid;
}
if (Low > High)
{
cout << "Not Found" << endl;
break;
}
}
}
Like this.
like this,if (Num = Stu[0][Mid])
{
Cout << "School Registration" << "<< Stu[0][Mid]<" The name of the student is "<< Name[Mid] <<" and the number is "<<<Stu[1]<"< "Number <<<<"
break;
}
The results of this part keep coming out. Even if you change the input value, only the mid value is printed out Can you tell me which part is wrong?
c++
if (Num = Stu[0][Mid])
Change the code above as below.
if (Num == Stu[0][Mid])
=
is the substitution operator, and ==
is the comparison operator.
© 2024 OneMinuteCode. All rights reserved.