To print two index in a sentence
-
CString isWrong = _T(" is wrong");
CString andMsg = _T(" and ");bool bCorrect\[4\]; int numOfFalse = 0; for(int i=0; i<4; i++){ bCorrect\[i\] = true; if(arrA\[i\] != arrB\[i\]){ bCorrect\[i\] = false; numOfFalse++; } } for(int i=0; i<4; i++){ if((bCorrect\[i\] == false) && (numOfFalse == 2)) { strRslt.Format("Q%d", i+1); m\_listRslt.AddString(strRslt + isWrong); } }
I want to print out something like Q1 and Q2 is wrong. Can anyone teach me ?
-
CString isWrong = _T(" is wrong");
CString andMsg = _T(" and ");bool bCorrect\[4\]; int numOfFalse = 0; for(int i=0; i<4; i++){ bCorrect\[i\] = true; if(arrA\[i\] != arrB\[i\]){ bCorrect\[i\] = false; numOfFalse++; } } for(int i=0; i<4; i++){ if((bCorrect\[i\] == false) && (numOfFalse == 2)) { strRslt.Format("Q%d", i+1); m\_listRslt.AddString(strRslt + isWrong); } }
I want to print out something like Q1 and Q2 is wrong. Can anyone teach me ?
-
if((bCorrect[i] == false) && (numOfFalse == 2))
{
strRslt.Format("Q%d%sQ%d%s", i, andMsg, i + 1, isWrong);
printf("%s\n", strRslt);
}Assume the false value is random assign in the array. The program will check by itself which index has a 'false' then print out the index number. For example, index 0 and 3 have 'false', then print out "Q1 and Q4 is wrong"
-
Assume the false value is random assign in the array. The program will check by itself which index has a 'false' then print out the index number. For example, index 0 and 3 have 'false', then print out "Q1 and Q4 is wrong"
Try this, which keeps track of the number that are false:
strRslt = "";
int wrong = 0;
for(int i=0; i<4; i++)
{
if(bCorrect[i] == false)
{
if (wrong++ > 0)
strRslt.AppendFormat("%s", andMsg);
strRslt.AppendFormat("Q%d", i + 1);
}
}
if (wrong > 0)
{
strRslt.AppendFormat("%s", isWrong);
printf("%s\n", strRslt);
} -
CString isWrong = _T(" is wrong");
CString andMsg = _T(" and ");bool bCorrect\[4\]; int numOfFalse = 0; for(int i=0; i<4; i++){ bCorrect\[i\] = true; if(arrA\[i\] != arrB\[i\]){ bCorrect\[i\] = false; numOfFalse++; } } for(int i=0; i<4; i++){ if((bCorrect\[i\] == false) && (numOfFalse == 2)) { strRslt.Format("Q%d", i+1); m\_listRslt.AddString(strRslt + isWrong); } }
I want to print out something like Q1 and Q2 is wrong. Can anyone teach me ?
Try (not tested, but you get the idea)
bool bAlreadyIncorrect = false;
for(int i=0; i<4; i++)
{
if ( bCorrect[i] == false )
{
if ( bAlreadyIncorrect )
m_listRslt.AddString(" and ");strRslt.Format("Q%d", i+1); m\_listRslt.AddString(strRslt); bAlreadyIncorrect = true;
}
}if (bAlreadyIncorrect)
m_listRslt.AddString( " is wrong");"In testa che avete, Signor di Ceprano?" -- Rigoletto