Outputs all zero's

Hello,
I am learning about array's. I have a program that should take in a user specified number of variables, in this case numerical grade points, assign it to a component and output its total sum. then display out each variable entered related to its place in the array.
My problem, i put in five different grade points and get out all zero's....

any suggestions are greatly appreciated.
------********----------

#include<iostream>
using namespace std;

void show_all_grades_entered(int grades, int grades_in_array[]);
int total_sum_of_grades(int grades, int grades_in_array[]);

int main()
{
int enter_grade=0;
int grades=0;
int i=0;
int total_sum=0;
int grades_in_array[50]={0};

cout<<"\nEnter maximum number of grades using arrays (No More than 50) ";
cin>>grades;

for (i=0; i<grades;++i)
{
cout<<"\nEnter grade #"<<i+1<<" ";
cin>>enter_grade;
}
total_sum = total_sum_of_grades( grades, grades_in_array);

cout<<"\nTotal sum of all grades entered "<< total_sum <<endl;
cout<<'\n';

show_all_grades_entered(grades, grades_in_array);
return 0;
}

int total_sum_of_grades(int grades, int grades_in_array[])

{int i;
int total_sum=0;
for(i=0;i<grades;++i)
{
total_sum +=grades_in_array[i];
}
return total_sum;
}

void show_all_grades_entered(int grades,int grades_in_array[])
{int i;
for(i=0;i<grades;++i)
{
cout<<"\n Display grades entered in element array["<<i<<"] "<<grades_in_array[i]<<endl;
}
cout<<'\n';
}
Hi tanmn38,

Firstly, edit your post so it uses code tags - the <> button on the right.


If you have any compile errors, post these in full as well

The first problem is that you don't store the entered values into the array.

With variable / function names - I like to use Camel Case - like this:

GradesSum
PrintGrades


Notice no underscores (name is too long), capitalise the first letter of a word. You are allowed to abbreviate a bit - put a comment at the declaration to describe what the variable is for.

Names like this total_sum_of_grades could be better IMO. Total & Sum mean the same thing, of isn't really needed because they are all "something of something".

Hope this helps a bit - I look forward to seeing your new code. :)
Topic archived. No new replies allowed.