J
jdcrief
I have all of this program working except for the pointer arithmetic
part, I think. This program should average the student's grades
together using pointer arithmetic and then display the student's and
their average grade. I do know that I will need to delete the array to
avoid a memory leak, but I am stuck on this part of the program. I am
open to any suggestions.
#include "stdafx.h"
#include <iostream>
#include <stdio.h>
using std::cin;
using std::cout;
using std::endl;
int main ()
{
int max;
int index;
int result;
int sum;
int avg;
cout<<"How many grades will you be entering? ";
cin>>max;
for (index = 0; index < max; index++)
{
cout << "\nPlease Enter Grades: ";
// store value into numbers array
cin >>numbers[index];
cout<<index+1<<". "<<numbers[index]<<endl;
sum =sum +numbers[index];
}
cout<<"\nStudent's Grade Total: "<<sum;
avg = sum/max;
cout<<"\nStudent's Grade Average: "<<avg<<endl;
return 0;
}
part, I think. This program should average the student's grades
together using pointer arithmetic and then display the student's and
their average grade. I do know that I will need to delete the array to
avoid a memory leak, but I am stuck on this part of the program. I am
open to any suggestions.
#include "stdafx.h"
#include <iostream>
#include <stdio.h>
using std::cin;
using std::cout;
using std::endl;
int main ()
{
int max;
int index;
int result;
int sum;
int avg;
cout<<"How many grades will you be entering? ";
cin>>max;
for (index = 0; index < max; index++)
{
cout << "\nPlease Enter Grades: ";
// store value into numbers array
cin >>numbers[index];
cout<<index+1<<". "<<numbers[index]<<endl;
sum =sum +numbers[index];
}
cout<<"\nStudent's Grade Total: "<<sum;
avg = sum/max;
cout<<"\nStudent's Grade Average: "<<avg<<endl;
return 0;
}