I need to have a for loop counter that should replace the number with a text when it's divisible by a set of numbers. I already have the loop and the code working, but the '\r' in my printf function does not work someone else's compiler.
Here is my code and outputs from different compilers so you can identify the issue better.
#include <stdio.h>
void hey(void)
{
for (int i = 50; i <= 100; i++)
{
printf("%d", i);
if (i % 5 == 0)
{
printf("\rHEY1 ");
}
if (i % 40 == 0)
{
printf("\rHEY2 ");
}
if (i % 40 == 0 && i % 5 == 0)
{
printf("\rHEY3 ");
}
printf("\n");
}
}
int main(void)
{
hey();
return 0;
}
This's the result on my compiler, which is how I exactly want:
and this one is how it appears on the online compiler that my teacher uses to mark:
For some reason, it doesn't remove the number to replace with 'Hey' in the other compiler. Instead, prints it on a new line.
How do I fix this? It should remove the number and print the letters instead of it as it's on the first screenshot. TIA.