I Was Working On Small Program In C Language. It Should Get How Many Hours User Has Worked In A Week(Input) Then Display Salary(output) Based On It. Problem Is That I Want To Make Infinite Loop To Make Sure That User Write Numbers Only In Input Like This:
int hours;
// get input
while(1)
{
printf("How Many Hours You Worked This Week: ");
if(scanf("%u", &hours))
break;
else
printf("oops, Write Integers Only not string or chars\n");
}
But Problem Is That When User Write Wrong Input It Execute Else And Then Repeat Loop, But It Doesn't Stop To Ask For Input Again! It Just Keep Repeating. I Think It Is Problem With \n char And Scanf (I Always Have Problem With This Func :)). I Will Be Happy If You Help!