im just new on c program

can you help me on this ?

problem :
make a C program that will ask 10 numbers and store into an array. the numbers to be entered must be between 70 to 95 only

output the average,number of grades below average, above average. if more grades are below average , will display " review your lesson" else " proceed to next chapter "

Dani AI

Generated

Short, practical guidance that builds on the replies from , and : collect ten valid integer grades (70-95 inclusive), store them in an array, compute the average as a floating value, count how many grades are strictly below and strictly above that average, and finally print either "review your lesson" when more grades are below or "proceed to next chapter" otherwise. Input should be re-prompted until ten valid values are collected and non-numeric or out-of-range entries must be rejected.

Implementation notes and common pitfalls: read lines with fgets and parse with strtol to avoid scanf-related troubles; always check for no-conversion and leftover characters; compute average as double (avoid integer division); treat grades equal to the average as neither below nor above; ties (equal counts) fall into the "proceed to next chapter" case per the problem wording.

A straightforward, robust example (C99):

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

int main(void) {
    int grades[10];
    const int MIN = 70, MAX = 95;
    char buf[128];
    int n = 0;

    while (n < 10) {
        printf("Enter grade #%d (%d-%d): ", n+1, MIN, MAX);
        if (!fgets(buf, sizeof buf, stdin)) return 1;
        char *endptr;
        long v = strtol(buf, &endptr, 10);
        if (endptr == buf) { printf("Not a number. Try again.\n"); continue; }
        while (isspace((unsigned char)*endptr)) endptr++;
        if (*endptr != '\0') { printf("Trailing characters. Try again.\n"); continue; }
        if (v < MIN || v > MAX) { printf("Out of range. Try again.\n"); continue; }
        grades[n++] = (int)v;
    }

    int sum = 0;
    for (int i = 0; i < 10; i++) sum += grades[i];
    double avg = sum / 10.0;
    int below = 0, above = 0;
    for (int i = 0; i < 10; i++) {
        if (grades[i] < avg) below++;
        else if (grades[i] > avg) above++;
    }

    printf("Average: %.2f\nBelow: %d\nAbove: %d\n", avg, below, above);
    if (below > above) printf("review your lesson\n");
    else printf("proceed to next chapter\n");
    return 0;
}

Compile with gcc -std=c99 -Wall -Wextra -o grades grades.c. Typical debugging steps: print the array and average after input, verify integer vs. floating division, and watch array indexing (0..9). This follows the stepwise approach suggested earlier and provides a safe input flow for beginners.

Recommended Answers

All 3 Replies

In your post is " review your lesson" which I find interesting. This class should have been building up to this bigger app. Where are you with this assignment? Are you stuck with a specific step?

commented: im stuck with a specific step i dont know what to do with it, im just a newbie on this program c ,i dont know what to start (T.T) +0

If you can post what has you stuck, either the code that isn’t working or pseudo code if you’re completely stuck with the language, we can help you out. We are here to help and gladly do, but we will not do the work for you.

FIrst things first. Figure out how to compile a C program.

Next step would be to solve each problem one at a time.
1) Figure out how to get the numbers from the terminal into the C program
2) Figure out how to get the numbers into an array
3) Figure out how to validate that the number that has been entered is between 70 and 95. If it is not then don't put it in the array
4) Figure out how to loop through the array and sum all the values in the array. This will help calculate the average
5) Find grades that are below the average you calculated in the previous step and display the message "review your lesson"
6) Find grades that are above average and display "Procees to next chapter"
7) Review your code and begin abstracting common concepts.
8) Rinse and repeat.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.