I have code but i'm having some difficulties.
I need to use the output of my IF statement in a calculation. But how can i extract the output from the IF statement in my code?
#include <iostream>
#include <cmath>
usingnamespace std;
int main(int argc, char *argv[]) {
double x, y, z;
cout<<"Please enter the student's three test grades:"<<endl;
cin>>x>>y>>z;
double maximum = max (x,y);
cout<<"This is the max:" <<maximum<<endl;
double maximum1 = max (y,z);
if (x>maximum1)
cout<<"This is the second max:" <<maximum1<<endl;
elseif (x<maximum1 && y>z && maximum==maximum1)
cout<<"This is the second max:" <<z<<endl;
elseif (x<maximum1 && y<z && maximum==maximum1)
cout<<"This is the second max:" <<y<<endl;
else
cout<<"This is the second max:" <<z<<endl;
int average=(((maximum+z)/2.0)+0.5);
cout<<"The student's average is:" <<average<<endl;
if (average>=90)
cout<<"Student has an A score.";
elseif (average<90 && average>=80)
cout<<"The student has a B score.";
elseif (average<80 && average>=70)
cout<<"THe student has a C score.";
elseif (average<70 && average>=60)
cout<<"The student has a D score.";
elseif (average<60)
cout<<"The student has an F score.";
return 0;
}
If you look at the middle of the code, there's an IF statement followed by an average calculation: int average=(((maximum+z)/2.0)+0.5); I want to replace z with the output of the IF statement before it.
Sorry for the lack of coherence, assignment due soon.
#include <iostream>
#include <algorithm> //for swap
usingnamespace std;
template <typename T>
void sortThree(T& max, T& mid, T& min)
{
if (max < mid) swap(max, mid);
if (mid < min) swap(mid, min);
if (max < mid) swap(max, mid);
}
int main(int argc, char *argv[])
{
double x, y, z;
cout<<"Please enter the student's three test grades:"<<endl;
cin>>x>>y>>z;
sortThree(x, y, z);
//at this point, x holds the biggest value, y the middle value, and z holds the smalled value
cout<<"This is the max:" << x <<endl;
cout<<"This is the second max:" << y <<endl;
int average= (x + y + z) / 3.0;
cout<<"The student's average is:" <<average<<endl;
if (average>=90)
cout<<"Student has an A score.";
elseif (average>=80)
cout<<"The student has a B score.";
elseif (average>=70)
cout<<"THe student has a C score.";
elseif (average>=60)
cout<<"The student has a D score.";
else
cout<<"The student has an F score.";
return 0;
}