Confused About Program Any Ideas?

k=0;
numberOfIncompletes;
while (k < nIncompletes && !numberOfIncompletes)
{
if(incompletes[k] == studentID)
numberOfIncompletes
k++;
}

Heres the given instructions:
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
an int variable numberOfIncompletes ,

Write code that counts the number of times the value of studentID appears in incompletes and assigns the value to numberOfIncompletes .
Only k , incompletes , nIncompletes , studentID , and numberOfIncompletes can be used.

If anyone can see any obvious mistakes or something (I'm kinda new to programming) much help is appreciated.

I don't know if you figured it out yet or not but i have the solution. First I'm not sure if that's your whole program but I started by setting my variables. I choose these.

const int nIncompletes = 10;
int k = 0;
int incompletes [nIncompletes] = {1, 32, 32, 45, 45, 45, 6, 6, 7, 10} ;
int student;
int numberOfIncompletes = 0;

then i got input for student variable

cout <<" enter student number" << endl;
cin >> student;

as for your while loop first you want to get rid of && !numberOfIncompletes. you dont need that. The rest of the loop looks good but you want to have numberOfIncompletes++ after the if statement. This increments the number of incompletes by when the if statement is true

while(k < nIncompletes)
{
if(incompletes[k] == student)
numberOfIncompletes++;
k++;
}

usually you want to check if the program is working correctly so I added this.

cout << " number of incompletes = " << numberOfIncompletes << endl;

I hope this helps.
Topic archived. No new replies allowed.