It keeps saying : The variable " Middle isn't initialised !!>> Any help <<?

#include <iostream>
using namespace std;

void main ()
{
float mt1 , mt2 , mt3 , fnal , q1 , q2 , q3 ,q4 , q5 , percent;
float total = 0;
float small , middle , large;


int intper;
char grade;
cout << " Please enter the student's grades " << endl;
cout << " Midterm 1: ";
cin >> mt1;
cout << " Midterm 2: ";
cin >> mt2;
cout << " Midterm 3: ";
cin >> mt3;
cout << " Quiz 1: ";
cin >> q1;
cout << " Quiz 2: ";
cin >> q2;
cout << " Quiz 3: ";
cin >> q3;
cout << " Quiz 4: ";
cin >> q4;
cout << " Quiz 5: ";
cin >> q5;
cout << " Final exam: ";
cin >> fnal;

if (( mt1 < mt2 ) && ( mt2 < mt3) )
{
mt1 = small;
mt2 = middle;
mt3 = large;
}
if ( ( mt2 < mt3 ) && ( mt3 < mt1 ) )
{
mt2 = small;
mt3 = middle;
mt1 = large;
}
if ( ( mt3 < mt2) && ( mt2 < mt1 ) )
{

mt3 = small;
mt2 = middle;
mt1 = large;

}
if ( ( mt1 < mt3 ) && ( mt3 < mt2) )
{
mt1 = small;
mt3 = middle;
mt2 = large;
}
if ( ( mt3 < mt1 ) && ( mt1 < mt2 ) )
{
mt3 = small;
mt1 = middle;
mt2 = large;
}
if ( (mt2 < mt1 ) && ( mt2 < mt3 ) )
{
mt2 = small;
mt1 = middle
mt3 = large;
}




total += middle + large + q1 + q2 + q3 + q4 + q5 + fnal;
percent = ( total / 450.0 ) * 100;
intper = percent / 10;
switch ( intper )
{
case 10:
case 9: grade = 'A'; break;
case 8: grade = 'B'; break;
case 7: grade = 'C'; break;
case 6: grade = 'D'; break;
default:grade = 'F';
}

cout << " Your pecentage is: " << percent;
cout << " ,and your final grade is: " << grade << endl;
system("pause");

}

mt1 = middle
should be
mt1 = middle;
that's okay but still the problem of initialisation not solved yet
Run-Time Check Failure #3 - The variable 'middle' is being used without being initialized.
This is where you declared 'middle'

float small , middle , large;

You never initialized it, i.e. gave it a value like this....

middle = 0;

The first time you use it is here...

mt2 = middle;

mt2 can't be set to the value of middle because middle has no value... i.e. it hasn't been initialized!

Did you mean this?
middle = mt2;
Last edited on
closed account (ivDwAqkS)
change float middle; to float middle = 0.0; and also change mt1 = middle to mt1 = middle; coz you forgot to close the statement with the ;
Last edited on
When I initialised middle, large and small with zero, they remained zero all over the program even if I assigned them to mt1,mt3 and mt2 l. and this happened when I debuged: Please enter the student's grades
Midterm 1: 100
Midterm 2: 100
Midterm 3: 100
Quiz 1: 10
Quiz 2: 10
Quiz 3: 10
Quiz 4: 10
Quiz 5: 10
Final exam: 200
Your pecentage is: 55.5556 ,and your final grade is: F
Press any key to continue . . .
#include <iostream>
using namespace std;

void main ()
{
float mt1 , mt2 , mt3 , fnal , q1 , q2 , q3 ,q4 , q5 , percent;
float total = 0.0;
float small = 0.0;
float middle = 0.0;
float large = 0.0;


int intper;
char grade;
cout << " Please enter the student's grades " << endl;
cout << " Midterm 1: ";
cin >> mt1;
cout << " Midterm 2: ";
cin >> mt2;
cout << " Midterm 3: ";
cin >> mt3;
cout << " Quiz 1: ";
cin >> q1;
cout << " Quiz 2: ";
cin >> q2;
cout << " Quiz 3: ";
cin >> q3;
cout << " Quiz 4: ";
cin >> q4;
cout << " Quiz 5: ";
cin >> q5;
cout << " Final exam: ";
cin >> fnal;

if (( mt1 < mt2 ) && ( mt2 < mt3) )
{
small = small + mt1;
middle = middle + mt2;
large = large + mt3;
}
if ( ( mt2 < mt3 ) && ( mt3 < mt1 ) )
{
small = small + mt2;
middle = middle + mt3;
large = large + mt1;
}
if ( ( mt3 < mt2) && ( mt2 < mt1 ) )
{

small = small + mt3;
middle = middle + mt2;
large = large + mt1;

}
if ( ( mt1 < mt3 ) && ( mt3 < mt2) )
{
small = small + mt1;
middle = middle + mt3;
large = large + mt2;
}
if ( ( mt3 < mt1 ) && ( mt1 < mt2 ) )
{
small = small + mt3;
middle = middle + mt1;
large = large + mt2;
}
if ( (mt2 < mt1 ) && ( mt2 < mt3 ) )
{
small = small + mt2;
middle = middle + mt1;
large = large + mt3;
}




total += middle + large + q1 + q2 + q3 + q4 + q5 + fnal;
percent = ( total / 450.0 ) * 100;
intper = percent / 10;
switch ( intper )
{
case 10:
case 9: grade = 'A'; break;
case 8: grade = 'B'; break;
case 7: grade = 'C'; break;
case 6: grade = 'D'; break;
default:grade = 'F';
}

cout << " Your pecentage is: " << percent;
cout << " ,and your final grade is: " << grade << endl;
system("pause");

}

Topic archived. No new replies allowed.