Answer the question
In order to leave comments, you need to log in
Why does the loop (C language) work incorrectly?
#include<stdio.h>
main()
{
/*4.28*/
int earnings, wagesperunit, wages, hourly, hours, cod, i, numberofunits;
for(i=1;i<=5;i++){
printf("Enter the cod of worker: ");
cod=getchar();
switch(cod){
case '1':
printf("Enter the wages for administrator: ");
scanf("%d",&wages);
printf("Wages is: %d\n",wages);
break;
case '2':
printf("Enter the business hours: ");
scanf("%d",&hours);
printf("Enter the hourly: ");
scanf("%d",&hourly);
hourly=hourly*40;
if(hours>=40)
hourly=hourly+((hours-40)*1.5);
printf("Wages is: %d\n",hourly);
break;
case '3':
printf("Enter the earnings: ");
scanf("%d",&earnings);
earnings=earnings*0.057+250;
printf("Wages is: %d\n", earnings);
break;
case '4':
printf("Enter wages per unit: ");
scanf("%d", &wagesperunit);
printf("Enter number of units: ");
scanf("%d", &numberofunits);
wagesperunit=wagesperunit*numberofunits;
printf("Wages is: %d\n", wagesperunit);
break;
case '\n': case ' ':
break;
default:
printf("Incorrect letter cod. Enter a new cod.\n");
break;
}
}
return 0;
}
Answer the question
In order to leave comments, you need to log in
An extra 'Enter' remains in the buffer, then it works
case '\n': case ' ':
break;
and you find yourself again at the invitation to enter the code. Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question