Hi all, need some suggestions. This code looks like a jumbled mess to me. I am missing something and am not sure what.

-Main should determain the letter grade of an average based on a 10-point scale and print out this grade.

``````90–100 A
80–89 B
70–79 C
60–69 D
0–59 F
``````

-FindAverage will get the average of the grades and return the average to GetGrades.
-GetGrades will return this average to main.

``````#include <iostream>

using namespace std;

// Function Prototypes.
void FindAverage(int,int);

int main()// Determine letter grade of the average.
{
int score;
int totalPoints;
int average;
int num;

while (score >= 0)
{
totalPoints += score;   // Accumulate the running total.
if (totalPoints >= 90) // 90 and above
else if (totalPoints >= 80) //80-89
else if (totalPoints >= 70) //70-79
else if (totalPoints >= 60) //60-69
else if (totalPoints >= 0)

cout << "Total Score: " << totalPoints << endl;
total = FindAverage(average,num);
}

return 0;
}

{
cout << "How many grades would you like to enter? ";
cin >> num;

while (num >> 0)
{
// Call Function.
total = FindAverage(average, num)
}

}
void FindAverage(int average,int totalPoints,int num)
{
// Display the average.
average = (totalPoints)/num;
cout << "The average of the numeric grades you entered is: " << average << endl;
}
``````

## All 7 Replies

The code you have for that function does this:
Uses the right shift operator in the while condition, which makes no sense.
Tries to find the average of that single grade, which makes no sense.

Just do what the requirement says:

``````GetGrades()
{

cout << "Enter number of grades" << endl;

vector<int> grades; // to store the input numbers
{
cout << "Enter grade " << i << endl;
}

// And so on
...
``````

Just code what the requirements say, one line at a time.

It says numberOfGrades, grade, and average are uninitialized in the main function.
My new code:

``````#include <iostream>

using namespace std;

// Function Prototypes.
int FindAverage(int,int);

int main()// Determine letter grade of the average.
{
int totalPoints;
int average;

{
totalPoints += numberOfGrades;   // Accumulate the running total.
if (totalPoints >= 90 && totalPoints ==100) // 90 and above
else if (totalPoints >= 80 && totalPoints== 100) //80-89
else if (totalPoints >= 70 && totalPoints== 79) //70-79
else if (totalPoints >= 60 && totalPoints==69) //60-69
else if (totalPoints >= 0 && totalPoints== 59) //0-59
cout << "Total Score: " << totalPoints << endl;
}

return 0;
}

{
cout << "How many grades would you like to enter? ";

{
}
// Call Function.
cout << "The average of the numeric grades you entered is: " << average << endl;

}
{
// Display the average.
}
``````

Why are you creating the variable `numberOfGrades` in `main`? Why does your `main` function contain some kind of running total? If the requirements you stated earlier are what you have to do, just do that. You're only confusing yourself with extra junk that wasn't asked for.

I haven't gotten to vectors yet.

vector<int> grades; // to store the input numbers

Have you got as far as `new` and arrays?

I do not think I am understanding the instructions given to me in the first place. The instructions look convoluted and messy to me. My teacher makes no sense and allows no questions.

-Write a program that prompts a user for their grades, finds the average and prints out a letter grade.
-The program calls a function called GetGrades that will read in grades from the keyboard, the number of grades should also be input by the user.
-GetGrades will find the sum of those grades and pass the sum and number of grades to another function called FindAverage.
-FindAverage will find the average of the grades and return this average to GetGrades.
-GetGrades will return this average to main.
-The main function will then determine the letter grade of that average based on a 10-point scale and print out this grade.
90–100 A
80–89 B
70–79 C
60–69 D
0–59 F

Thank you for your help. Functions are tricky beasts and I got variables confused.

``````#include <iostream>

using namespace std;

// Function Prototypes.
int FindAverage(int,int);

int main()// Determine letter grade of the average.
{
int averageGrade = 0; // Accumulator

else
cout << "Invalid Entry." << endl;

return 0;
}
{
int average = 0;

cout << "How many grades would you like to enter? " << endl;

for (int i = 1;i <= numberOfGrades; i++)
{
}
// Call Function.