Asking for input until its valid

i got this code where i try to help the teacher to calculate the grades of the students bases on given tasks :

#include <stdio.h>

#define PASS 55
#define MAX_NUM_OF_STUDENTS 10
#define NUM_OF_TASKS 4

int main() {
    int i, j, num_of_students, grade;
    float highestGrade = 0, lowestGrade = 100, passedCount = 0;
    float taskPercentages[NUM_OF_TASKS] = {0}; // Array to store task percentages
    float totalGrades[MAX_NUM_OF_STUDENTS] = {0}; // Array to store total grades

    printf("Welcome to our grading system!n");

    // Take the percentage of each task and check for invalid input.
    for (i = 0; i < NUM_OF_TASKS; i++) {
        while (1) {
            printf("Please enter the percentage of task %d:n", i + 1);
            if (scanf("%f", &taskPercentages[i]) != 1) {
                printf("Input Errorn");
            } else if (taskPercentages[i] < 0 || taskPercentages[i] > 1) {
                printf("Maximum percentage is 1 and minimum percentage is 0. Please try again!n");
            } else {
                break;
            }
        }
    }

    // Calculate the sum of task percentages.
    float sumWeight = 0.0;
    for (i = 0; i < NUM_OF_TASKS; i++) {
        sumWeight += taskPercentages[i];
    }

    // Ensure the sum weight of the tasks is exactly 1.
    if (sumWeight != 1.0) {
        printf("The sum weight of the tasks is %.2f and it should be 1. Please try again!n", sumWeight);
        return 1;
    }

    printf("How many students in your class?n");
    while (1) {
        if (scanf("%d", &num_of_students) != 1) {
            printf("Input Errorn");
        } else if (num_of_students < 1 || num_of_students > MAX_NUM_OF_STUDENTS) {
            printf("Maximum number of students in a course is %d and minimum 1. Please try again!n", MAX_NUM_OF_STUDENTS);
        } else {
            break;
        }
    }

    // Get students' grades and calculate the total grade.
    for (i = 0; i < num_of_students; i++) {
        totalGrades[i] = 0.0;
        printf("Please enter student %d grades.n", i + 1);
        for (j = 0; j < NUM_OF_TASKS; j++) {
            while (1) {
                printf("Enter grade %d:n", j + 1);
                if (scanf("%d", &grade) != 1) {
                    printf("Input Errorn");
                } else if (grade < 0 || grade > 100) {
                    printf("Maximum grade is 100, minimum grade is 0. Please try again!n");
                } else {
                    totalGrades[i] += grade * taskPercentages[j];
                    break;
                }
            }
        }

        if (totalGrades[i] > highestGrade) highestGrade = totalGrades[i];
        if (totalGrades[i] < lowestGrade) lowestGrade = totalGrades[i];
        if (totalGrades[i] >= PASS) passedCount++;
    }

    float sumGrades = 0.0;
    for (i = 0; i < num_of_students; i++) {
        sumGrades += totalGrades[i];
    }
    float averageGrade = sumGrades / num_of_students;

    printf("Number of students: %dn", num_of_students);
    printf("Percentage of each task:n");
    for (i = 0; i < NUM_OF_TASKS; i++) {
        printf("Task %d: %.2fn", i + 1, taskPercentages[i]);
    }
    printf("nThe grades are:n");
    for (i = 0; i < num_of_students; i++) {
        printf("Student %d: %.2fn", i + 1, totalGrades[i]);
    }
    printf("nHighest grade: %.2fn", highestGrade);
    printf("Lowest grade: %.2fn", lowestGrade);
    printf("Average: %.2fn", averageGrade);
    printf("Number of passing students: %.0fn", passedCount);
    printf("Thank you for using our system!n");

    return 0;
}

the output i am supposed to get in this specific input :

0.5 0 0 0.6 -1 v

is :

Welcome to our grading system!
Please enter the percentage of task 1:
Please enter the percentage of task 2:
Please enter the percentage of task 3:
Please enter the percentage of task 4:
The sum weight of the tasks is 1.10 and it should be 1. Please try again!
Please enter the percentage of task 1:
Maximum percentage is 1 and minimum percentage is 0. Please try again!
Input Error!

but my output is coming as :

Welcome to our grading system!
Please enter the percentage of task 1:
Please enter the percentage of task 2:
Please enter the percentage of task 3:
Please enter the percentage of task 4:
The sum weight of the tasks is 1.10 and it should be 1. Please try again!

my output dosen’t allow the user to give new input , whenever i try to fix it and combine them in the same loop i get runtime error .

any recommendations ?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật