How do I make this add up all the grades?
For example, if you line command 2, you enter 2 grades, so I input 7 and 3, but I want to add them up to become 10, How should I do this?
#include<iostream>
2 #include<stdlib.h>
3
4 using namespace std;
5
6 int main (int argc, char *argv[]){
7 int *grades, sum;
8
9 if (argc > 1){
10
11 grades = new int[atoi(argv[1])];
12
13 for(int i=0; i < atoi(argv[1]); i++){
14 cout<<"Enter grade: ";
15 cin>> grades[i];
16
17 sum+=grades[i];
18 }
19
20 cout<<grades<<endl;
21
22 }
23 return 0;