im making a grade book code using functions and SINGLE arrays (multi arrays would be easier, but my teacher wants this in our code)

from main() ask the user for info about 4 students
---> use functions getStudentInfo() 4x (once per student; im assuming this will have the students names)
----> call ComputerAverage() 4x from main (average of students grades. they will have 5 grades, where the lowest will be dropped and then averaged together)
----> call PrintGradeInfo() 4x as well to print grade, pausing in between each student so user can view all info (pause is a function as well)

example of output:

Enter Name of Student: Billy Bob
Score 1: 100
Score 2: 100
Score 3: 100
Score 4: 100
Score 5: 100

here is grade info:

Billy Bob
Exam Scores: 100 100 100 100 100
Average: 100
Grade: A

Hit enter key to continue...
(it should show this once the data for all 4 students entered)

for the names i will be using the getline function
and using a for loop to drop the lowest score and each student has its own 1 dimensional array

this is my concept so far:

#include <iostream>
#include <string> // for student names
using namespace std;

//function prototypes
void GetStudentInfo(string& name, int scores[]);
int LowestScore (const int scores[]);
void ComputeAveAndGrade (const int scores[], double& average, char& grade);
void PrintGradeInfo (const string& name, const int scores[], double average, char grade);
void Pause(); 

int main()

// function calls
GetStudentInfo (name[0], scoreS0);
DetermineGrade (scoreS0. average[0], grade[0]);
PrintStudentInfo(name[0], scoreS0, average[0], grade[0]);
// there are more to call, this is just the beginning since i have 4 students

return 0;

// functions here

this is how the layout should be according to my professor, but she didnt elaborate much as to WHY it should be like this
all the code that is in green is the ones that i am confused on (like why are passed by references being used? and what will the array do??)
im also confused on how to write the functions and strings itself (my book does a pathetic job by taking only 2 pages to cover strings)

if you could explain to me what is going on in the code-it would really help me understand!

thanks guys! :-)

8 Years
Discussion Span
Last Post by mrboolf

help me please!!!
i need to understand this-its gonna be on my exam!!!


You already have access to arrays and they go great with loops when you want to do the same thing over and over and over. You know you want to get and manipulate information on 4 students. So I'd use a loop to get the same information four times by calling the needed functions once each time through the loop.

When calling functions with elements of the array as parameters you can frequently use the loop counter as the index of the array to indicate which element of the array you will be using this time through the loop.

You want to send some of the parameters by reference so changes made to the parameters in the functions you've called are maintained back in the calling function.

Be sure you declare all the variables you are going to use from within main before you try to send them as parameters to the various functions.


^^um...that didnt help. sorry. can someone help by showing how the code should be (or an example?)
i know that arrays are like pointers but how does it apply to the particular code i am trying to work on right now?


^^um...that didnt help. sorry. can someone help by showing how the code should be (or an example?)
i know that arrays are like pointers but how does it apply to the particular code i am trying to work on right now?

Well, it should have helped at least a little. Lerner gave you some ideas to help get you started. You don't HAVE any code right now. You have prototypes and and function calls. EVERYTHING is in green, so presumably you don't understand any of it, and presumably since you didn't ask Lerner to elaborate but rather simply said that his answer didn't help, I imagine you didn't understand what he was getting at with the idea of a loop and you didn't understand what he was talking about when he mentioned that you had to declare all the variables before you pass them from main either.

Do you know how to use arrays? Do you know how to pass a variable by reference, and when to do so? Do you know how to use a loop and use the loop counter variable as an array index?


i havent used arrays yet nor strings but i have used functions before. basically its the arrays that throws me off. what is an array index?

int myArray[10];
myArray[0]= 1;

That is the array index, note arrays are 0 index'ed meaning the first entry is always at 0 never 1



I think you need to read up on some tutorials on strings and arrays. Here are some links that may be helpful.


Here's a sample program that may help you get started.

#include <iostream>
#include <string>
using namespace std;

int main ()
    string names[4];
    for (int i = 0; i < 4; i++)
        cout << "Enter name " << i << " : ";
        cin >> names[i];
    cout << "Here are the names. " << endl;
    for (int i = 0; i < 4; i++)
        cout << "Name " << i << " : ";
        cout << names[i] << endl;

    return 0;

dude pls help me with this... i always got a parse error

its almost like this program


Well, @ nido24:

1 - You shouldn't post your questions in other's threads
2 - When you'll start your own thread asking for help, make sure you put a real question in there! It's not like we have a crystal ball nor like we can access to your machine and search your program - if you encounter errors post your code and explain what it's wrong with it. Don't use expressions like "it's almost like this program". What's almost ?
3 - Just to make sure you ever read of this: use code tags when posting code (and yes, do post your code when asking for help)

To the OP:

Here are a couple of other links that you could read to learn how to use arrays and strings:
http://cplus.about.com/od/learning1/ss/strings_2.htm and following pages

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.