samedi 28 mai 2022

the code still print 0 and it can't calculate the required task

#include <iostream>
using namespace std;

int main()
{
    int n, G;
    float num[500], sum=0.0, average,Grades;

    cout << "Enter the numbers of data: ";
    cin >> n;

    while (n > 500 || n <=  0)
    {
        cout << "Error! number should in range of (1 to 500)." << endl;
        cout << "Enter the number again: ";
        cin >> n;
    }

    for(G = 0; G < n; ++G)
    {
        cout << G + 1 << ". Enter number: ";
        cin >> num[G];
        sum += num[G];
    }


    average = sum / n;
    Grades = num[G] >= average;
    
    cout<<endl;
    
    cout << "Grades Average = " << average << endl;
    cout << "Grades above or equal the Average : " <<Grades<< endl;
    cout << "Number of grades above the Average = "<<(int) Grades;
    
    return 0;
}

i coded this code but the Number of grades above the Average and Grades above or equal the Average don't work it just print 0

i tried to print the Grades >= the avg but it print 0

also num of Grades also print 0

where is the error ?

Aucun commentaire:

Enregistrer un commentaire