program in C++

Problem :GPA (Graded Programming Assignment): It is of 10 marks. Students need to write some code and submit it. There are 3 test cases, against which the student's program is checked, and the marks are awarded. If the student's submission passed all three test cases, then 1 mark is awarded; if two testcases are passed then, 0.6 marks are awarded; if only one test case is passed, then 0.3 marks are awarded; and finally 0 marks are awarded, if no testcase passes. This means that the student can score from 0 (lowest), 0.3, 0.6, and 1 (highest).

int numOfStudents: Integer number containing the total number of students
float gpa[]: Array of type float containing the GPA marks of all students
int sum_gpa[]: Integer array to be computed
The function should do the following

Count the number of students who scored 'y' marks in GPA.
Store the result in the array, 'sum_gpa[]'.
E.g. 1: If 20 students scored 1 mark in GPA, then sum_gpa[3] = 20
E.g. 2: If 10 students scored 0.6 marks in GPA, then sum_gpa[2] = 10
E.g. 3: If 19 students scored 0.3 marks in GPA, then sum_gpa[1] = 19
E.g. 4: If 42 students scored 0 marks in GPA, then sum_gpa[0] = 42

I wrote this program but still something wrong it doesn't count the number of students and store it in n,m,k,l and the statement for invalid input is not correct. Please help
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
 #include <iostream>
using namespace std;
int main()
{
  int k=0,l=0,m=0,j=0,n=0,numberOfStudents,sum_gpa[4];
  float gpa[ numberOfStudents];
  cout << "Enter the number of students";
  cin >> numberOfStudents;
for (j=0; j< numberOfStudents ;j++)
{
   cout << " Enter GPA of students";
      cin >> gpa[numberOfStudents];
      /*if (gpa[j] != 0 || gpa[j] != .3 || gpa[j] != .6 || gpa[j] != 1)  cout << "Invalid GPA";*/
      

      if (gpa[j]=0.0)   { (n = n+1) ; }
      else if (gpa[j]=0.3){   (k=k+1) ; }
      else if (gpa[j]=0.6) { (l=l+1) ; }
      else {  (m=m+1) ; }
}
sum_gpa[0]=n;
sum_gpa[1]=k;
sum_gpa[2]=l;
sum_gpa[3]=m;
cout << n;
}

variable += variable is the operation to tell it to store
variable to store totals in += variable you want to total
Topic archived. No new replies allowed.