HELP ME WITH MY PROGRAM

44 10 [Error] incompatible types in assignment of 'int' to 'float [5]'
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[Error][Error][Error][Error][Error][Error][Error][Error][Error][Error][Error]
#include<iostream>
#include<string>
using namespace std;

void display(int mgrade[5], int fgrade[5], float cgrade[5])
{
cout << "===============Gradin Management System===============" << endl;
cout << " Name MG FG CG" << endl;
cout << "Midterm Grades:" << endl;
for (int i=0; i < 5; ++i)
{
cout << "\t\t\t" << mgrade[i] << "\t\t" << fgrade[i] << "\t\t" << cgrade[i] << endl;
}

cout << "===============Gradin Management System===============" << endl;
}


int main()
{

int mgrade[5],fgrade[5];
float cgrade[5];

for (int i=0; i<5; i++)
{
cout << " Enter Midterm Grade " << i + 1 << " : " << endl;
cin >> mgrade[i];
}

for (int i=0; i<5; i++)
{
cout << " Enter Final Grade " << i + 1 << " : " << endl;
cin >> fgrade[i];
}

for (int i=0; i<5; i++)
{
cgrade = mgrade[i]*(1/3) + fgrade[i]*(2/3);
}
system("cls");
system("pause");
display(mgrade, fgrade, cgrade);
return 0;
}

cgrade = mgrade[i]*(1/3) + fgrade[i]*(2/3);
should be cgrade[i]
you also need to static_cast<float> the right hand side numerators, otherwise integer division would just give (truncated) integer results:
1
2
    int a = 7;
    std::cout << a/3 << "\n";//prints 2 
cgrade[i] = mgrade[i]*(1.0/3.0) + fgrade[i]*(2.0/3.0);

Avoid magic numbers like 5 everywhere in the code, make them a const variable instead:

const unsigned int Size = 5;

or if you have c++ 11, constexpr:

constexpr unsigned int Size = 5;

Could also use constexpr for constants like 1.0 / 3.0 .

Prefer double rather than float.

double cgrade[Size];
Topic archived. No new replies allowed.