For my homework I have to create a program with functions and nexted while loops. I have got most of the program written but it's not executing how I want it to. The program is setup as a football program, (RB = Running Back it's a football playing position)
it first ask the user number of weeks which must be more then 0 but less than 7;
next it ask for the RB's name, if x is typed the program terminates;
then it asks for the number of yards for that week;
then it displays the RB's name the week number and a row of stars with each star counting for 10 yards;
the program goes through all the weeks then displays the RB's name and the maximum yards he/she got in a week.
then it executes the loop again asking for the RB's name, if x is typed the program terminates; etc.
I'm having four problems so far.
1) After entering the number of weeks, name and yardage it displays the name and yardage again but with the answers then asks for next weeks yardage.
2) It never displays the maximum yards.
3) It asks for the next RB's name put instead of asking for their yardage it asks the next RB's name.
4) When x is entered at the beginning it displays that the maximum yardage is 0 I'd rather it didn't display anything.
#include <iostream>
#include <string>
using namespace std;
void det_max(int yards,int max)
{
if (yards >= max)
max = yards;
}
void showRByards(string playername, int weekno, int yards, int stars)
{
cout << "Input a RB Name: (or type x to stop)" << playername <<
endl;
cout << "Input Week " << weekno <<"'s yardage : "<< yards <<
endl;
cout << "Yards for the week: " << yards << endl;
cout << playername << "'s rushing yardage for week " << weekno << ": " ;
stars = yards/10;
int j = 0;
while (j<stars)
{
cout << "*";
j++;
}
cout << endl;
}
int main ()
{
int max = 0;
int count = 0;
int weekno = 1;
string name;
string playername = " ";
// Variable for player names
int weeks, yards, stars;
cout << "Input the number of weeks: ";
cin >> weeks;
if (weeks>0 && weeks<7)
{
while (playername != "x")
{
cout << "Input the RB name (or type x to stop): ";
cin >> playername;
while (count<weeks)
{
count++;
cout << "Input Week " <<weekno<<"'s yardage : ";
cin >> yards;
det_max(yards,max);
showRByards(playername,weekno,yards,stars);
weekno++;
}
}
cout << playername<<"'s best week was with "<<max << "yards.";
}
else
cout <<"Invalid number of weeks." <<endl;
return 0;
}