This is the problem statement:
HackerLand University has the following grading policy:
Every student receives a 'grade' in the inclusive range from 0 to 100. Any 'grade' less than '40' is a failing grade.
Sam is a professor at the university and likes to round each student's 'grade' according to these rules:
If the difference between the 'grade' and the next multiple of 5 is less than 3, round 'grade' up to the next multiple of 5. If the value of 'grade' is less than 38, no rounding occurs as the result will still be a failing grade.
For example ' grade= 84 ', will be rounded to 85 but 'grade = 29' will not be rounded because the rounding would result in a number that is less than '40'.
Given the initial value of 'grade' for each of Sam's 'n' students, write code to automate the rounding process.
#include<iostream>
using namespace std;
int main()
{
int n,x;
cin >> n;
for (int i = 0; ++i; i < n)
{
if(x >= 38)
{
cin >> x;
int y = x;
while(1)
{
if (y % 5 == 0)
break;
y++;
}
if (y - x <= 2)
{
x=y;
}
}
cout << x << "\n";
}
return 0;
}
The code runs fine every time i input a value more than or equal to 38 but as soon as I input a lesser value an infinite loop is encountered displaying the input number .
Please tell me why i am i getting this error and how to fix it.