我正在尝试根据统计数据编写一个“评分”NFL接收器的代码。这是一个相对简单的程序,我正在为一个类项目,并可能逃脱我在Matlab中得到的错误(它没有运行在while循环。基本上,它显示YPC但停止一旦它击中而循环)。但是,我希望有一个有效的代码。请指出我犯错误的地方!谢谢
yards = input('Yards per game/season: ');
rec = input('Receptions per game/season: ');
long = input('Longest reception per game/season: ');
TD = input('Touchdowns per game/season: ');
YPC = (yards/rec);
display('Average Yards per Catch (YPC): ');
display(YPC);
grade = 0;
while YPC >= 1
if YPC >= 5.7 %NFL Average YPC
grade = grade + 50; %Gives Reciever a 50 baseline rating if above average YPC
else
grade = grade + 25; %Gives Reciever a 25 baseline rating if below average YPC
if long >= 67.4 %NFL Average Longest Reception
grade = grade + (long/8); %Adds the longest reception divided by 8 to the grade if above average Long
else
grade = grade - (long/16); %Subtracts the longest reception in 16 games from the grade if below average Long
if TD >= 7.75 %NFL Average TD/Recievers
grade = grade + ((TD * 10)/16); %Adds the number of touchdowns times 10, divided by 16 games if above average TDs
else
grade = grade + ((TD * 7)/16); %Adds the number of touchdows times 7, divided by 16 games if below average TDs
end
end
end
end
display(grade);
答案 0 :(得分:1)
也许这就是你要找的东西:
YPC = 2;
while YPC >= 1
yards = input('Yards per game/season: ');
rec = input('Receptions per game/season: ');
long = input('Longest reception per game/season: ');
TD = input('Touchdowns per game/season: ');
YPC = (yards/rec);
display('Average Yards per Catch (YPC): ');
display(YPC);
grade = 0;
if YPC >= 5.7 %NFL Average YPC
grade = grade + 50; %Gives Reciever a 50 baseline rating if above average YPC
else
grade = grade + 25; %Gives Reciever a 25 baseline rating if below average YPC
if long >= 67.4 %NFL Average Longest Reception
grade = grade + (long/8); %Adds the longest reception divided by 8 to the grade if above average Long
else
grade = grade - (long/16); %Subtracts the longest reception in 16 games from the grade if below average Long
if TD >= 7.75 %NFL Average TD/Recievers
grade = grade + ((TD * 10)/16); %Adds the number of touchdowns times 10, divided by 16 games if above average TDs
else
grade = grade + ((TD * 7)/16); %Adds the number of touchdows times 7, divided by 16 games if below average TDs
end
end
end
display(grade);
end
这将让您计算新输入值的新等级。在循环开始时会询问新值,退出时只给每场游戏码数值0。