C++ question on comparing elements on 2 different arrays
Well, what is the question?
oh that is strange the rest of the question not there. sorry question is how to compare elements of 2 string arrays. one array is holding all the correct answers to a test. second array is holding all the answers from the students. The student receives points if the elements are the same from the two arrays
well if your question is how to compare elements of two different arrays then all you need to do is: for(int i=0;i<n;i++) { if(arr1[i]==arr2[i]) cout<<i<<"th element matches in both the arrays"; else cout<<i<<"th element in array 1 is "<<arr1[i]<<" and in array 2 is "<<arr2[i]; } here arr1[] is array 1, arr2[] is array 2 and i is a counter variable.
Because this is string data, the answers need to have their case set too. Either compare them as all uppercase or all lowercase or you'd have to get into Regular Expressions. This URL should help with the comparisons: http://www.cplusplus.com/reference/cstring/
Join our real-time social learning platform and learn together with your friends!