I've been having trouble with this because the snippet of code in the else portion is being displayed even if the condition of the if statement was correct.
Here's the code:
cout << "\n";
cout << setw(35) << left << "\n";
cout << "0=====================================================0";
cout << setw(35) << left << "\n";
cout << "0------------------- Modify Contact ------------------0";
cout << setw(35) << left << "\n";
cout << "0=====================================================0\n\n";
cout << setw(35) << left << "\n";
cout << "Search by First Name: ";
cin >> xfirst_name;
rewind(fp);
while (fread(&e,recsize,1,fp) == 1)
{
if (strcmp(e.first_name,xfirst_name) == 0)
{
cout << setw(35) << left << "\n";
cout << "Record Found! ";
cout << setw(35) << left << "\n";
cout << "_____________________________________________________ ";
cout << setw(35) << left << "\n\n";
cout << " First Name: ";
cin >> e.first_name;
cout << setw(35) << left << "\n";
cout << " Last Name: ";
cin >> e.last_name;
cout << setw(35) << left << "\n";
cout << " Mobile Number: ";
cin >> e.p_number;
cout << setw(35) << left << "\n";
cout << "---------------------- Address ----------------------";
cout << setw(35) << left << "\n";
cout << " House Number: ";
cin >> e.house_number;
cout << setw(35) << left << "\n";
cout << " Barangay: ";
cin >> e.barangay;
cout << setw(35) << left << "\n";
cout << " City: ";
cin >> e.city;
cout << setw(35) << left << "\n";
cout << " Province: ";
cin >> e.province;
cout << setw(35) << left << "\n";
cout << " Country: ";
cin >> e.country;
cout << setw(35) << left << "\n";
cout << " ZIP Code: ";
cin >> e.zip_code;
fseek(fp, - recsize, SEEK_CUR);
fwrite(&e, recsize, 1, fp);
break;
}
else
{
SetColor(12);
cout << setw(35) << left << "\n";
cout << "XXXXXXXXXXXXXXX RECORD NOT FOUND XXXXXXXXXXXXXXX";
}
}
I've been having trouble with this because the snippet of code in the else portion is being displayed even if the condition of the if statement was correct.
How do you know the condition was found to be true? Do you see "Record Found!" on the screen?