Prinitng to many times to the screen

Hi, got an assignment from varsity. I've got most of the program to work but its printing to the screen 5 times and I only want it to print once.

Eg:
cos1512: 57.00%
mat1512: 86.50%
inf1520: 65.10%
cos1521: 78.40%
inf1505: 89.10%

but I get:

Semester Marks:
================

cos1512: 57.00%
mat1512: 57.00%
inf1520: 57.00%
cos1521: 57.00%
inf1505: 57.00%
cos1512: 86.50%
mat1512: 86.50%
inf1520: 86.50%
cos1521: 86.50%
inf1505: 86.50%
cos1512: 65.10%
mat1512: 65.10%
inf1520: 65.10%
cos1521: 65.10%
inf1505: 65.10%
cos1512: 78.40%
mat1512: 78.40%
inf1520: 78.40%
cos1521: 78.40%
inf1505: 78.40%
cos1512: 89.10%
mat1512: 89.10%
inf1520: 89.10%
cos1521: 89.10%
inf1505: 89.10%

My code:

#include <iostream>

using namespace std;

class Module
{
public:
void setModules(string module1, string module2, string module3, string module4, string module5);
void setMarks(int aMark1, int aMark2);
int updateMarks();
void calcSemesterMark(double & semesterMark);
void display(double & semesterMark);
Module();


private:
string modules[5], module;
int mark1, mark2, semesterMark;

};

int main()
{
Module modules[5];
double semesterMark = 0;
int mark2;

cout << "Semester Marks:" << endl;
cout << "================" << endl << endl;


modules[0].setMarks(50, 55);
modules[1].setMarks(90, 85);
modules[2].setMarks(77, 60);
modules[3].setMarks(84, 76);
modules[4].setMarks(66, 99);

for (int j = 0; j < 1; j++)
{
for (int i = 0; i < 5; i++)
{
modules[i].setModules("cos1512", "mat1512", "inf1520", "cos1521", "inf1505");
modules[j].updateMarks();

//Values are set to 2 decimal places
cout.precision(2);
cout.setf(ios::fixed);

modules[i].calcSemesterMark(semesterMark);
modules[i].display(semesterMark);
}
}
return 0;
}

//Calculates the semester mark and returns the value
void Module::calcSemesterMark(double & semesterMark)
{
double assign1, assign2, total;

assign1 = (mark1 / 100.00) * (30 / 100.00);
assign2 = (mark2 / 100.00) * (70 / 100.00);

total = assign1 + assign2;

semesterMark = total * 100;

}

//Updates the mark for cos1512 by 5%
int Module::updateMarks()
{
for (int i = 0; i < 5; i++)
{
if (modules[i] == "cos1512")
mark2 = mark2 + 5;
}
return mark2;
}

//Displays the semester marks and modules to the screen
void Module::display(double & semesterMark)
{
for (int i = 0; i < 5; i++)
{
cout << modules[i] << ": " << semesterMark << "%" << endl;
}
// cout << modules[0] << ": " << semesterMark << "%" << endl;
//cout << modules[1] << ": " << semesterMark << "%" << endl;
//cout << modules[2] << ": " << semesterMark << "%" << endl;
//cout << modules[3] << ": " << semesterMark << "%" << endl;
//cout << modules[4] << ": " << semesterMark << "%"<< endl;
}

//Sets the values in the array
void Module::setModules(string module1, string module2, string module3, string module4, string module5)
{
modules[0] = module1;
modules[1] = module2;
modules[2] = module3;
modules[3] = module4;
modules[4] = module5;
}

void Module::setMarks(int aMark1, int aMark2)
{
mark1 = aMark1;
mark2 = aMark2;
}



//Constructor
Module::Module()
{
module = "";
mark1 = 0;
mark2 = 0;
semesterMark = 0;
}

Any help would be appreciated. Thanks
Let me examine it
nvm it has classes and I dont know how to use them just yet. :(
Just think of a class as a variable that contains data and functions, where the ones you can access are marked public.

So to use the fucntions in the class just declare an instance of it and then use that variable to call each fucntion.


Module myModule;

myModule.SetMarks(85, 93);
I did do that.

Module modules[5];

then I called it too -

modules[0].setMarks(50, 55);

The problem I'm getting is, it's printing the marks 5 times for each module, I only want it to do it once.

Thanks
Topic archived. No new replies allowed.