Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The following program has three separate errors, each of which would cause an in

ID: 3629436 • Letter: T

Question

The following program has three separate errors, each of which would cause an infinite loop. As a member or the inspection team, you could save the programmer a lot of testing time by finding the errors during the inspection. Can you help?

#include <iostream>
void Increment(int);
int main()
{
int count = 1;
while (count < 10)
std::cout << " The number after " << count;
Increment (count);
std::cout << " is " << count << std::endl;
return 0;
}

void Increment (int nextNumber)
{
nextNumber++;
}

Explanation / Answer

please rate - thanks


#include <iostream>
void Increment(int);
int main()
{
int count = 1;
while (count < 10)
{std::cout << " The number after " << count;     //increment(count) not in loop so never called
Increment (count);      }                                   //missing { } as placed, count not updated
std::cout << " is " << count << std::endl;
return 0;
}

void Increment (int nextNumber)
{
nextNumber++;                   //void function so number is not being incremented should be int and return int
}

----------

corrected code

#include <iostream>
int Increment(int);
int main()
{
int count = 1;
while (count < 10)
{std::cout << " The number after " << count<<endl;     //increment(count) not in loop so never called
count=Increment (count);      }                                   //missing { } as placed, count not updated
std::cout << " is " << count << std::endl;
return 0;
}

int Increment (int nextNumber)
{
nextNumber++;                   //void function so number is not being incremented should be int and return int

return nextNumber;

}