gpt4 book ai didi

c++ - 我的棒球程序应该可以运行,但我就是找不到为什么它不能运行的问题。查看程序

转载 作者:行者123 更新时间:2023-11-28 03:54:12 24 4
gpt4 key购买 nike

这个程序使用数组来保存 9 局的棒球比分。它计算每局的高分队和比赛的总冠军。

#include <iostream>
#include <string>
#include <iomanip>
using namespace std;

const int n = 9;

void PrintInput(char[], int[], char[], int[]);
void InningWinner(char[], int[], char[], int[]);

int main()
{
int scores1[n];
int scores2[n];
char team1[n], team2[n];

PrintInput(team1,scores1,team2,scores2);
InningWinner(team1,scores1,team2,scores2);

return 0;
}

void PrintInput(char t1[], int s1[], char t2[], int s2[])
{
cout << "\n********************************************************************\n";

cout << "Team 1: " << t1 << " ";
for (int i = 0; i < n; i++){
cout << setw(5) << s1[i];
}
cout << "\n";
cout << "Team 2: " << t2 << " ";
for (int i = 0; i < n; i++){
cout << setw(5) << s2[i];
}
}

void InningWinner(char t1[], int s1[], char t2[], int s2[])
{
for (int i = 0; i < n; i++){
if (s1[i] > s2[i])
cout << endl << t1 << " Wins Inning " << i + 1 << endl;
else if (s2[i] > s1[i])
cout << endl << t2 << " Wins Inning " << i + 1 << endl;
else if (s1[i] == s2[i])
cout << endl << " Inning " << i+1 << " ends in a TIE" << endl;
}
}

最佳答案

您所有的数组都在没有显式初始化的情况下使用,这将产生未定义的结果。

关于c++ - 我的棒球程序应该可以运行,但我就是找不到为什么它不能运行的问题。查看程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4262689/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com