Im an idiot bear with me

So I am new (as in week one of a class) to c++ and my assignment is to create a console application that prompts for the user to enter their name, then to enter 10 grades ranging from 0.0 to 100.0, then to display all the grades along with their name and point to the highest and lowest grades. My professor provided a skeleton which is
#include "stdafx.h"
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
 
int _tmain(int argc, _TCHAR* argv[])
{
// define the variables and the arrays you need


cout << "Please enter your name (80 characters max):\n";
cin.getline(studentName, MAX, '\n');

cout << "Please enter ten grades to one decimal point:\n";

// loop to read in the grades and store them into an array

// determine the higest and the lowest grade
cout << "Student " << studentName << "\n"
<< "Highest Grade: " << *hgrade << "\n"
<< "Lowest Grade: " << *lgrade << "\n";

system("pause");
return 0;
}

my questions are: how to create the loop and limit it to 10 entries
is float grades [10]an appropriate definition of the array and limiting the elements to 10

If there are resources or tutorials you would recommend I am all ears, learning this from a text with no face to face is challenging. Thanks and sorry for the noob question
> my questions are: how to create the loop and limit it to 10 entries

A loop like this will execute 10 times:
1
2
3
4
for( int i = 0 ; i < 10 ; ++i )
{
    // read a grade into position i in the array
}



> is float grades [10]an appropriate definition of the array and limiting the elements to 10

Yes. Favour double over float double grades[10] ;


This probably contains a bit more than what your professor asked you to do:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <iostream>
#include <iomanip>

int main()
{
    // define the variables and the arrays you need
    const int MAX_NAME_LEN = 80 ;
    const int MAX_NAME_SZ = MAX_NAME_LEN + 1 ; // +1 for the terminating null character
    const int NGRADES = 10 ; // number of grades
    const double MIN_GRADE = 0.0 ;
    const double MAX_GRADE = 100.0 ;

    char name[MAX_NAME_SZ] = "" ; // array to hold the name.
    double grades[NGRADES] ; // array to hold the grades.
    for( int i = 0 ; i < NGRADES ; ++i ) grades[i] = MIN_GRADE ; // to start with, set all the grades to MIN_GRADE


    std::cout << "Please enter your name (" << MAX_NAME_LEN << " characters max):\n";
    std::cin.getline( name, MAX_NAME_SZ );

    if( std::cin.fail() ) // if more than MAX_NAME_LEN characters were entered
    {
        // http://en.cppreference.com/w/cpp/io/basic_ios/clear
        std::cin.clear() ; // clear the error flag

        // http://en.cppreference.com/w/cpp/io/basic_istream/ignore
        std::cin.ignore( 10000, '\n' ) ; // throw away the remaining characters in that line
    }

    std::cout << "Please enter " << NGRADES << " grades to one decimal point:\n";

    // loop to read in the grades and store them into an array
    // determine the highest and the lowest grade

    double lowest_grade = MAX_GRADE ;
    double highest_grade = MIN_GRADE ;

    for( int i = 0 ; i < NGRADES ; ) // NGRADES times
    {
        std::cout << "grade #" << i+1 << ": " ;
        std::cin >> grades[i] ; // note: if input fails, we leave the remaining grades as MIN_GRADE

        if( grades[i] >= MIN_GRADE && grades[i] <= MAX_GRADE ) // if the grade is valid
        {
            if( grades[i] < lowest_grade ) lowest_grade = grades[i] ;
            if( grades[i] > highest_grade ) highest_grade = grades[i] ;
            ++i ; // increment i to move to the next grade
        }
        else std::cout << "grade must be between " << MIN_GRADE << " and " << MAX_GRADE << '\n' ;
    }

    std::cout << "\nStudent " << name << "\n"
                 // http://en.cppreference.com/w/cpp/io/manip/setprecision
              << std::fixed << std::setprecision(1) // print exactly one digit after the decimal point
              << "Highest Grade: " << highest_grade << "\n"
              << "Lowest Grade: " << lowest_grade << "\n";
}

Now, try to write the program on your own.
Topic archived. No new replies allowed.