The code below is to display the value of a,b,c,d to four decimal places and the value of e to one decimal place. However, when I run the function, all five variables are in one decimal place. Can you tell me what's wrong with my code and how can I fix it?
#include <iomanip>
#include <algorithm>
#include <vector>
struct Record{
int year;
string name;
string team;
double completions, attempts, yards, touchdowns, interceptions, e;
};
void passerRate ()
{
double a, b, c, d, e;
//quarterbacks is a vector of struct
for (int i = 0; i < quarterbacks.size(); i++){
Record player = quarterbacks[i];
a = (player.completions / player.attempts - 0.3) * 5;
b = (player.yards / player.attempts - 3) * 0.25;
c = (player.touchdowns / player.attempts) * 20;
d = 2.375 - (player.interceptions / player.attempts * 25);
cout << fixed << setprecision(4); // I want to set the precision of a,b,c,d to four decimal places
e = (a + b + c + d) / 6 * 100;
cout << fixed << setprecision(1); //I want to set the precision of e to one decimal place
quarterbacks[i].e = e;
}