I need to round of a number (the input is guaranteed to be an integer & is positive) to the next multiple of 5.
I tried this:
int round = ((grade
Try this:
int num = grades[j] % 5 < 3 ? grades[j] - (grades[j] % 5) : grades[j] - (grades[j] % 5) + 5;
Here demo code:
#include
int main() {
//code
int grades[5] = {10, 68, 12, 67, 41};
int j;
for (j = 0; j < 5; j++)
{
int num = grades[j] % 5 < 3? grades[j] - (grades[j] % 5) : grades[j] - (grades[j] % 5) + 5;
printf("%d\n",num);
}
return 0;
}
Output:
10
70
10
65
40
I hope help you.