Mar 21, 2014 at 11:11pm UTC
#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");
}
Mar 21, 2014 at 11:23pm UTC
mt1 = middle
should be
mt1 = middle;
Mar 21, 2014 at 11:29pm UTC
that's okay but still the problem of initialisation not solved yet
Mar 21, 2014 at 11:31pm UTC
Run-Time Check Failure #3 - The variable 'middle' is being used without being initialized.
Mar 22, 2014 at 12:27am UTC
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 Mar 22, 2014 at 12:31am UTC
Mar 22, 2014 at 1:38am UTC
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 Mar 22, 2014 at 1:41am UTC
Mar 22, 2014 at 7:29am UTC
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 . . .
Mar 22, 2014 at 7:30am UTC
#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");
}