Below is the question, my code, and the error. Help is greatly appreciated! QUES
ID: 3640996 • Letter: B
Question
Below is the question, my code, and the error. Help is greatly appreciated!QUESTION:
Given
an int variable k ,
an int array incompletes that has been declared and initialized,
an int variable nIncompletes that contains the number of elements in the array,
an int variable studentID that has been initialized, and
an int variable numberOfIncompletes ,
Write code that counts the number of times the value of studentID appears in incompletes and assigns this value to numberOfIncompletes .
You may use only k , incompletes , nIncompletes , studentID , and numberOfIncompletes .
---------------------------------------------------------------------------------------------------------
MY CODE:
for(k = 0; k < nIncompletes; k++){
if(studentID = incompletes[k]){
numberOfIncompletes++;
}
}
THE ERROR MESSAGE I GET FROM CODELAB:
"Do not modify the value of nIncompletes or studentID."
Explanation / Answer
please rate - thanks
the error is because you have an = when should have a ==
in addition numberOfIncompletes is never initialzed to 0. but that may not be needed
numberOfIncompletes=0;
for(k = 0; k < nIncompletes; k++){
if(studentID == incompletes[k]){
numberOfIncompletes++;
}
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.