Using a for loop to input and output array values

so i got this piece of code today having some slight errors with it can you guys tell me how its actually done as i want to know where i have gone wrong here is the code ..
Using a for loop to input and output array values
*/

#include <stdio.h>


int main(void)
{
/* Declare an array of integers */
int Grades[5];
int nCount;

/* Populate the array */
for(nCount = 0; nCount < 5; nCount++)
{
printf("\nPlease enter a value for array element %d : ",nCount);
scanf("%d",&Grades[nCount]);
}

printf("\n\n"); /* Just a couple of lines to add a gap */

/* Display the array */
for(nCount = 0; nCount < 5; nCount++) /* Note that reusing nCount */
{
printf("Array element %d has the value %d\n", nCount, Grades[nCount]);
}

return 0;
}
I don't see anything immediately wrong with it.

What errors are you getting?
I don't think there is any errors with the code you've given.

...can you guys tell me how its actually done...


Its done exactly the way you've done it. In C++ its done like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>

using namespace std;

int main()
{
    int numbers[5];
    int counter;
    
    //Get the values
    for(counter = 0; counter < 5; counter++)
    {
        cout << "Enter value for element " << counter << ": ";
        cin >> numbers[counter];
    }
    cout << "\n";
    
    //Display the values
    for(counter = 0; counter < 5; counter++)
        cout << "The number at position " << counter << " is: " << numbers[counter] << endl;
        
    return 0;
}

I was to Extend the code such that it also counts all entered values in the range -10 to -120 inclusive.
The code should now record the maximum and minimum values within each of the three specified ranges.
not sure how to do that
Topic archived. No new replies allowed.