I'm trying to find a way to express this thing into a function because it's repeating almost same thing over and over again.Code:flag = 1; while(flag == 1) { printf("What is the student's Assignment 1 mark? :"); scanf("%d",&a1); if(a1>100||a1<0) { printf("Invalid mark. Please enter again\n"); flag = 1; } else { flag = 0; } } flag = 1; while(flag == 1) { printf("What is the student's Assignment 2 mark? :"); scanf("%d",&a2); if(a2>100||a2<0) { printf("Invalid mark. Please enter again\n"); flag = 1; } else { flag = 0; } } flag = 1; while(flag == 1) { printf("What is the student's Assignment 3 mark? :"); scanf("%d",&a3); if(a3>100||a3<0) { printf("Invalid mark. Please enter again\n"); flag = 1; } else { flag = 0; } }
Could anyone give me any suggestions?