C ++荣誉编程实验室

时间:2017-05-05 16:02:19

标签: c++

在我们班上我们正在做一个程序来保持保龄球分数,它需要使用功能,这是我到目前为止,但最后一个总计是关闭的,谢谢你的帮助没有人我知道可以弄清楚什么是错的。

#include <iostream>
#include <iomanip>

using namespace std;

void printHeader (void);

typedef struct {
    string name;
    int game1, game2, game3;
    int total;
    double average;
} Player;

Player readPlayer();
int computeTotal(Player thePlayer, int a, int b, int c);
double computeAverage(Player thePlayer, int a, int b, int c);

void computeSeriesData (Player &thePlayer);
void printPlayer(Player thePlayer);

int main (void)
{
    Player player1 = readPlayer();
    computeSeriesData(player1);
    Player player2 = readPlayer();
    computeSeriesData(player2);
    Player player3 = readPlayer();
    computeSeriesData(player3);
    Player player4 = readPlayer();

    cout << " " << endl;
    printHeader();
    printPlayer(player1);
    printPlayer(player2);
    printPlayer(player3);
    printPlayer(player4);

    return 0;
}    

Player readPlayer()
{
    Player NewPlayer;
    cout << "Player name: ";
    cin >> NewPlayer.name;
    cout << "Game one average: ";
    cin >> NewPlayer.game1;
    cout << "Game two average: ";
    cin >> NewPlayer.game2;
    cout << "Game three average: ";
    cin >> NewPlayer.game3;

    return NewPlayer;
}

void printPlayer(Player thePlayer)
{
    cout << setprecision(1);
    cout << fixed << showpoint << endl;
    cout << left << setw(11) << thePlayer.name << right << setw(12) <<         thePlayer.game1 << setw(12) << thePlayer.game2 << setw(12) << thePlayer.game3     << setw(12) << thePlayer.total << setw(14) << thePlayer.average << endl;
}

int computeTotal(int a, int b, int c)
{
    return a+b+c;
}

double computeAverage(int a, int b, int c)
{
    return (a+b+c) / 3.0;
}
void computeSeriesData (Player &thePlayer)
{
    thePlayer.average = computeAverage(thePlayer.game1, thePlayer.game2,     thePlayer.game3);
    thePlayer.total = computeTotal(thePlayer.game1, thePlayer.game2,     thePlayer.game3);
}

void printHeader (void)
{
    cout << "NAME                GAME 1      GAME 2      GAME 3          TOTAL       AVERAGE" << endl;
}

输出:

Player name:  Weber
Game one average:  212
Game two average:  220
Game three average:  190
Player name:  Fazio
Game one average:  195
Game two average:  235
Game three average:  210
Player name:  Patterson
Game one average:  195
Game two average:  215    
Game three average:  219    
Player name:  Martin
Game one average:  178
Game two average:  190
Game three average:  206

NAME                GAME 1      GAME 2      GAME 3      TOTAL       AVERAGE

Weber               212         220         190         622         207.3

Fazio               195         235         210         640         213.3

Patterson           195         215         219         629         209.7

Martin              178         190         206       32553           0.0

2 个答案:

答案 0 :(得分:2)

你错过了computeSeriesData(player4);

答案 1 :(得分:0)

不为player4

调用computeSeriesData