It’s fantasy football season and the running back position is vital to any champ
ID: 3750205 • Letter: I
Question
It’s fantasy football season and the running back position is vital to any championship team. The creators of the Supreme Fantasy football app want to develop a new function that ranks fantasy running backs. This ranking creates 4 tiers for running backs based on the number of 100-yard games they had in the previous season. The ranking tiers are described below. To execute this function the user will input the number of yards gained for each game the running back played (NFL season is 16 games). The number of games in which the back gained over 100 yards will determine what tier the player falls in. The C++ code should include at least 1 loop (for, while, or do while), a switch statement, and an if statement. The code should also display the total number of yards for all 16 games. An example of the desired display is also below.
Tier
Criteria
4
Less than 5 100-yard games
3
5 – 8 100-yard games
2
8 – 10 100-yard games
1
More than 10 100-yard games
Player x
Game yards
100
34
0
45
200
1
74
123
125
56
109
124
56
89
34
25
The total number of yards for player x is 1,195
Player x had 6 games of 100 or more yards
Player x is a Tier 3 running back
Tier
Criteria
4
Less than 5 100-yard games
3
5 – 8 100-yard games
2
8 – 10 100-yard games
1
More than 10 100-yard games
Explanation / Answer
#include<bits/stdc++.h>
using namespace std;
void display(int arr[],string str)
{
int i,count=0,sum=0,x;
for(i=0;i<16;i++)
{
if(arr[i]>=100)
{
count++;
}
sum=sum+arr[i];
}
cout<<"The total number of yards for player "<<str<<" is"<< sum<<endl;
cout<<"Player "<<str<<" had "<<count<<" games of 100 or more yards"<<endl;
if(count<5)
{
x=4;
}
else if(count>=5&&count<8)
{
x=3;
}
else if(count>=8&&count<10)
{
x=2;
}
else
{
x=1;
}
switch(x)
{
case 1:
{
cout<<"Player "<<str<<" is a Tier 1 running back";
}
break;
case 2:
{
cout<<"Player "<<str<<" is a Tier 2 running back";
}
break;
case 3:
{
cout<<"Player "<<str<<" is a Tier 3 running back";
}
break;
case 4:
{
cout<<"Player "<<" is a Tier 4 running back";
}
break;
}
}
int main()
{
int i,arr[16];
string name;
cout<<"Player: ";// print player write player name in this field;
cin>>name;
cout<<"Game Yards: ";
for(i=0;i<16;i++)
{
cin>>arr[i];
}
display(arr,name);
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.