Ok so my teacher is really bad at explaining things and then he gives us homework that is completely irrelevant I looked everywhere on google and could not find anything so I decided to make an account.
I need to display every 5th number from 0 to 50 using a loop but I have no idea please help? Thanks
#include <iostream>
int main()
{
for (unsignedshortint n{0}; n <= 50; n++)
{
// if the remainder of n divided by 5 is 0 then n is one of the 5th numbers
if ((n % 5) == 0)
{
std::cout << n << std::endl;
}
}
return 0;
}
Actually, 0 % 5 = 0, but it is the first and not the fifth number. I don't know if your teacher will care about that though. If you don't want to output 0 as a result, change it to n{1}.
Similarly, does the range 0 to 50 include the number 50 or not? If you don't want to output 50 as a result, change it to n < 50.