hurry_up_bumpman 2022-08-14 17:46 采纳率: 62.5%
浏览 28
已结题

c++输出问题初学者求解

本人初学

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

int main()
{
    string names[3] = { "z3,l4,w5" };
    int scores[3][3] =
    {
        {100,100,100 }, {90,50,100},{60,70,80}
    };
    for (int r = 0; r < 3; r++)
    {
        int sum = 0;
        for (int c = 0; c < 3; c++)
        {
            sum += scores[r][c];
            cout << scores[r][c] << "\t  ";
        }
        cout << names[r] << "total score is" << sum<<endl;
    }

    system("pause");

    return 0;
}

为啥输出是
100 100 100 z3,l4,w5total score is300
90 50 100 total score is240
60 70 80 total score is210
不应该是
100 100 100 z3,total score is300
90 50 100 l4,total score is240
60 70 80 w5total score is210
这样的吗,求解

  • 写回答

1条回答 默认 最新

  • 烟雨龙升 2022-08-14 17:52
    关注

    改一下

    
    string names[3] = { "z3","l4","w5" };
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 9月10日
  • 已采纳回答 9月2日
  • 创建了问题 8月14日