Nested for loop assistance?

Having trouble creating a nested for loop for three and two dimensional arrays.
Am I getting it wrong at some point in my program? I'm not entirely sure on how to go about creating a for loop with arrayforloops? I do not know how to organize it correctly

Would it be like:

(OUTER for loop on students)
{
----(2D Array string forloop){
--------(2D Array string forloop){
-------}
------}
---------(2D Array int forloop){
-------------(2D Array int forloop){
-------}
-------}
-------(MIDDLE for loop on course)
{
---------(3D Array double forloop){
-------------(3D Array double forloop){
-----------------(3D Array double forloop){
-------}
-------}
-------}
----------------------(INNER for loop on exams)
{
------------------------(2D Array char forloop){
---------------------------(2D Array char forloop){
-------}
-------}
}//end of inner loop
----------}Closed middle loop
}//Closed outerloop




Below in the program description and my sorry shameful attempt...
.............................................................................
/*--Two and three dimensional arrays to store all input and output data and fill these arrays by the data read from the input file and by the computed data. The data of all students will be stored in these arrays before writing it to the output file.
----A two dimensional array nonNumeric1 of type string -nonNumeric1 [3] [9]
----A two dimensional array numeric 1 of type int- numeric1 [3] [2].
----A three dimensional array numeric2 of type double to store input data (read from input file) for three students, three courses and five exams, and computed Numerical Grades. For three students it may look like
Numeric2 [3] [3] [6]
----A two dimensional array letterGrade of type char to store letter grades of three students and three courses. For three students and three courses it may look like letterGrade [3] [3].

• Read the input from the Input File. Report should be based on three students each taking three courses. It means that you will be using a nested “for” loop. The outer loop will be on students, the middle loop will be on courses and the inner loop will be on five Exams.
*/


for(int student = 1; student <= numstudent; student++)
----{
----for (int j =0; j < 3; j++){
-------for (int k = 0; k < 9; k++){
------------getline(inputFile, nonNumeric1[j][k]);
------------if (nonNumeric1[m][n].length() > 25)
------------{
-------------cout << "Error! Strings should must be 45 characters or less" << --------------endl;
--------------continue;
------------}
---------}
for (int age =0; age < 3; age++){
----for (int yrs = 0; yrs< 2; yrs++){
--------inputFile >> numeric1[agee][yrs];
---------inputFile.ignore();
--------if (numeric1[age][yrs] < 1 || numeric1[age][yrs] > 100)
---------{
----------cout << "Error! Numeric data must be between 1 and 100." << endl;
--------- break;
----------}
------}
}
for(int row = 0;row < 3; row++){
-----for(int column = 0; column < 3; column++){
---------for(int exam = 0; exam < 5; exam++){
------------inputFile >> numeric2[row][column][exam];
------------}
-----}
}
for(int tstudents = 0;tstudents < 3; tstudents++){
-----for(int tcourse = 0; tcourse < 3; tcourse++){
-----------inputFile >> letterGrade[tstudents][tcourse];
-------}
}
Last edited on
Topic archived. No new replies allowed.