I'm working on a program, part of which requires you to input grades for several students, which must be displayed as an array. I have it where the grades are entered like you would if there was no array, and then displayed them all as an array. However, whenever I run the program, it just regurgitates the list back. Is it possible to do it this way or do I have to enter the grades directly as an array? My teacher doesn't like to answer too many questions and I've been unable to find anything on the Internet.
Enter the grades: (3 rows) x (4 columns)
Row 1
Col 1: 20
Col 2: 50
Col 3: 60
Col 4: 30
Row 2
Col 1: 50
Col 2: 80
Col 3: 60
Col 4: 70
Row 3
Col 1: 20
Col 2: 60
Col 3: 30
Col 4: 40
Display as an array: (3 rows) x (4 columns)
20 50 60 30
50 80 60 70
20 60 30 40
#include<iostream>
#include<iomanip>
usingnamespace std;
int main(){
int array[3][4];
//inputs the grades
std::cout << "\nEnter the grades: (3 rows) x (4 columns)\n\n";
for (int i=0; i < 3; i++)
{
std::cout << "Row " << i + 1 << '\n';
for (int j=0; j < 4; j++)
{
std::cout << " Col " << j + 1 << ": ";
std::cin >> array[i][j];
}
std::cout <<'\n';
}
//displays the input grades as an array
// ....here, try to modify your code to display data as an array...
return 0;
}
#include <iostream>
usingnamespace std;
int main ()
{
constint SizeOfArray = 4;//This will be the number of students grades you are entering
constint rows = SizeOfArray;//this line is not necessary and just used to help follow the program
int Grade1 [SizeOfArray];
int Grade2 [SizeOfArray];
//This is you assigning the test results for each student.
for (int i = 0; i < rows; i++)
{
cout << "Please enter student " << i+1 << ", 1st grade: ";
cin >> Grade1 [i];
cout << "Please enter student " << i+1 << ", 2nd grade: ";
cin >> Grade2 [i];
}
//this outputs the results of each student. each row represents a different student's results.
for (int i = 0; i < rows; i++)
{
cout << Grade1 [i] << "\t" << Grade2 [i] << endl;
}
int x;
cin >> x;
return 0;
}