gpt4 book ai didi

C++逻辑问题

转载 作者:太空宇宙 更新时间:2023-11-04 14:41:44 25 4
gpt4 key购买 nike

<分区>

好久不见(去年的Java课)。因为我的学校不提供 C++,所以我一直在尝试自己学习 C++。我写了一个简单的程序只是为了测试我到目前为止学到的东西——实际上只是语法——在我进入中间的东西之前。无论如何,我只是想强调,我从不寻找答案,我宁愿你质疑我的后勤工作,这样我就可以重新考虑事情,并可能自己完成。我认为既然我可以用 Java 成功地编写这个,那么在 C++ 中一切都会很好,但我遇到了各种问题。我尝试调试并单步执行,但我仍然不明白为什么我的一些变量没有获得我分配给它们的值。如果您能指出正确的方向,我将不胜感激。

// This program will create any number of teams the user chooses, 
// give each a score and calculate the average of all the teams.

#include <iostream>
using namespace std;

int main(){

//number of teams
int teamCount;
//array to keep scores
int team[0];
//total of scores
int total=0;
//average of all scores
int average=0;

cout<<"How many teams do you want to keep scores of?"<<endl;

cin>>teamCount;

//cout<<teamCount;

//ask the person for the score as many time
//as there are teams.
for(int i=0; i<teamCount; i++){
cout<< "Give me the score of team "<< i+1<<":"<<endl;
cin>>team[i];

total+=team[i];
}

average = teamCount/total;

//output the list of the scores
for(int i=0; i<teamCount; i++){
cout<<"Team "<<i+1<<" score is:"<<team[0]<<endl;
}

cout<<"and the average of all scores is "<<average<<endl;

return (0);

}

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