Visual C++ homework question
C / C++ / MFC
1
Posts
1
Posters
0
Views
1
Watching
-
// Based on the values keyed in at A, B, C, D, P, Q, // software check whether the answer at Q1, Q2, Q3 and Q4 is correct. // then software will print the 1 of following result in the list box. // "ALL CORRECT" // "Qx is wrong" // "Qx and Qy is wrong" // "Qx, Qy and Qz is wrong" // "ALL WRONG" // x,y,z should be replaced with the actual number. If only the answer for Q1 is wrong, we print "Q1 is wrong". Above is the question given and below is the code I'm doing. Can anyone tell me how to proceed or is there any mistakes in my code?
void CPractice4Dlg::OnBnClickedBtnTest()
{
CString strRslt;UpdateData(TRUE); m\_listRslt.ResetContent(); strRslt.Format("A = %d", m\_nA); m\_listRslt.AddString(strRslt); strRslt.Format("B = %d", m\_nB); m\_listRslt.AddString(strRslt); strRslt.Format("C = %d", m\_nC); m\_listRslt.AddString(strRslt); strRslt.Format("D = %d", m\_nD); m\_listRslt.AddString(strRslt); strRslt.Format("P = %d", m\_nP); m\_listRslt.AddString(strRslt); strRslt.Format("Q = %d", m\_nQ); m\_listRslt.AddString(strRslt); strRslt.Format("Ans Q1 = %d", m\_nAnsQ1); m\_listRslt.AddString(strRslt); strRslt.Format("Ans Q2 = %d", m\_nAnsQ2); m\_listRslt.AddString(strRslt); strRslt.Format("Ans Q3 = %d", m\_nAnsQ3); m\_listRslt.AddString(strRslt); strRslt.Format("Ans Q4 = %d", m\_nAnsQ4); m\_listRslt.AddString(strRslt); int arrA\[4\] = {m\_nAnsQ1, m\_nAnsQ2, m\_nAnsQ3, m\_nAnsQ4}; int Q1 = m\_nA && m\_nB; int Q2 = m\_nC || m\_nD; int Q3 = m\_nC >> m\_nP; int Q4 = m\_nD << m\_nQ; int arrB\[4\] = {Q1, Q2, Q3, Q4}; strRslt.Format("%d", Q1); m\_listRslt.AddString(strRslt); strRslt.Format("%d", Q2); m\_listRslt.AddString(strRslt); strRslt.Format("%d", Q3); m\_listRslt.AddString(strRslt); strRslt.Format("%d", Q4); m\_listRslt.AddString(strRslt); int count = 0; for(int i=0; i<4; i++){ if(arrA\[i\] == arrB\[i\]){ count++ ; } } bool found = false; for(int i=0; i<4; i++){ for(int j=0; j<4; j++){ if(arrA\[i\] == arrB\[i\]){ count++ ; } else if(!found && j==3){ strRslt.Format("Q%d is wrong", i+1); m\_listRslt.AddString(strRslt); } } }found = false; if(count == 4){ strRslt.Format("ALL CORRECT"); m\_listRslt.AddString(strRslt); }
}