2d array

hello

Program should any user how many students
Must use 2D Array

8 column & rows depend on student numbers
EXAMPLE:
First Name
Last Name
Grade 1
Grade 2
Grade 3
Grade 4
Average
Grade Letter
Li
Zuhi
90
90
98
77
88%

this is what i got so far
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <iostream>
#include <iomanip>
using namespace std;

void input (double &average) {
        int grades [4], sum= 0;
	cout<< "Input  five  grades : " << endl;
//For loop 
	 average = (sum) / 5;


}
void output(double average){

    cout.setf(ios::showpoint|ios::fixed);
    cout<<setprecision(1);

    cout<<"Your grade Average is "<<setw(8)<<average <<endl;

}
int main()

{

	if( average < 60)
	{
		cout<<"Your average is an F."<<endl;
	}
	else if( average >= 60 && average<= 69)
	{
		cout<<"Your average is a D."<<endl;
	}
	else if( average >= 70 && average<= 79)
	{
		cout<<"Your average is a C."<<endl;
	}
	else if( average >= 80 && average <= 89)
	{
		cout<<"Your average is a B."<<endl;
	}
	else if( average >= 90 && average<= 100)
	{
		cout<<"Your average is an A."<<endl;
	}

	else
	{
		cout<<"You have entered the grades incorrectly."<<endl;
	}
return 0;
}



thanks for help in advance




Last edited on
Program should any user how many students
Must use 2D Array

I don't see a 2D Array in your code.
Thats what i am trying to figure out .


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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
void input (int grade[]){
for (int i=0; i<4;, i++){
    cout<<"Input Student Grade :"<<i+1<<endl;
cin>> grade [i];

double average = (sum) / 5;

	if( average < 60)
	{
		cout<<"Your average is an F."<<endl;
	}
	else if( average >= 60 && average<= 69)
	{
		cout<<"Your average is a D."<<endl;
	}
	else if( average >= 70 && average<= 79)
	{
		cout<<"Your average is a C."<<endl;
	}
	else if( average >= 80 && average <= 89)
	{
		cout<<"Your average is a B."<<endl;
	}
	else if( average >= 90 && average<= 100)
	{
		cout<<"Your average is an A."<<endl;
	}

	else
	{
		cout<<"You have entered the grades incorrectly."<<endl;
	}

}
void output (int grade [] )}

cout<<" the grade output is :"<<grade<< "average is" <<averg<< [i]
{
int grade [4];

input (grade)
output(grade)



return 0;
}
Last edited on
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <iostream> 

using namespace std; 
int main()
{ 

	double Grade1; 
	double Grade2; 
	double Grade3;
	double Grade4;
	double AvgGrade; 
	double Total = 0; 
	int Students = 0; 
	int n = 0;

	cout << "Enter the number of students in class : "; 
	cin >> Students;

	while (n < Students) {


		cout << "Please enter four  grades for student  ";
		cin >> Grade1; 
		cin >> Grade2;
		cin >> Grade3; 
		cin >> Grade4; 


		
		Total = (Grade1 + Grade2 + Grade3+ Grade4);
		AvgGrade = (Total / 4); 

		cout <<  " grades: " << Grade1 << " " << Grade2 << " " << Grade3 <<" " << Grade4 <<  " average: " << AvgGrade << " "; 
		
		n = n + 1; 
		if ( AvgGrade >= 90) 
			cout << " letter grade: A!\n";
		else
			if ( AvgGrade >= 80) 
				cout << " letter grade: B.\n";
			else
				if ( AvgGrade >= 70)
					cout << " letter: grade: C.\n";
				else
					if ( AvgGrade >= 60)
						cout << " letter grade: D.\n";
					else 
						cout << " letter grade: F.\n";
		cout << "\n"; 
	}
		

	return 0;
	
}



this work but i want to use array, to display it was a table
8 column & rows depend on student numbers

You use a 2D array to store 8 scores for each of the eight students. Do you know how to do it?
no, i miss lecture on it
closed account (48T7M4Gy)
no, i miss lecture on it

Use the tutorials here then. If you have any trouble with that then come back for any help with your trial code. Good luck with your catchup study and testing.

http://www.cplusplus.com/doc/tutorial/arrays/
It doesn't talk about 2d array

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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <iostream>
using namespace std;

void printarray (int arg[], int length) {
  for (int n=0; n<length; ++n)
    cout << arg[n] << ' ';
  cout << '\n';
    double Grade1; 
	double Grade2; 
	double Grade3;
	double Grade4;
	double AvgGrade; 
	double Total = 0; 
	int Students = 0; 
	int n = 0;
	int stu;
		
		Total = (Grade1 + Grade2 + Grade3+ Grade4);
		AvgGrade = (Total / 4); 
		
		n = n + 1; 
		if ( AvgGrade >= 90) 
			cout << " letter grade: A!\n";
		else
			if ( AvgGrade >= 80) 
				cout << " letter grade: B.\n";
			else
				if ( AvgGrade >= 70)
					cout << " letter: grade: C.\n";
				else
					if ( AvgGrade >= 60)
						cout << " letter grade: D.\n";
					else 
						cout << " letter grade: F.\n";
						
	cout << "Enter the number of students in class : "; 
	cin >> Students;

	while (n < Students) {

        cout <<" input student number \n";
        cin>>stu;
		cout << "Please enter four  grades for student  ";
		cin >> Grade1; 
		cin >> Grade2;
		cin >> Grade3; 
		cin >> Grade4; 


		cout << "\n"; 
}

int main ()
{
int firstarray[] = {"Student number","Grade 1","Grade 2","Grade 3","Grade 4","Average"};
  int secondarray[] = {stu,  Grade1, Grade1, Grade1, Grade1, AvgGrade};
  printarray (firstarray,6);
  printarray (secondarray,6);
  return 0;
}
No, it is not a two-dimensional array. You are messing your code up.
ik because there is no example of 2d array, only multiple & other arrays
Topic archived. No new replies allowed.