Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/141.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 计算用户使用循环输入的整数数量 #包括 int main() { int cnt=0,sum=0,value=0; std::cout值) 总和+=数值; 标准::cout_C++_Loops_Integer_Using_Counting - Fatal编程技术网

C++ 计算用户使用循环输入的整数数量 #包括 int main() { int cnt=0,sum=0,value=0; std::cout值) 总和+=数值; 标准::cout

C++ 计算用户使用循环输入的整数数量 #包括 int main() { int cnt=0,sum=0,value=0; std::cout值) 总和+=数值; 标准::cout,c++,loops,integer,using,counting,C++,Loops,Integer,Using,Counting,解释的解决方案 为了计算所提供的整数数量,只要在给出新输入时向cnt添加1即可(见下面带有//**注释的行) 此外,不需要在开始时进行cnt==值检查(其中缺少一个“=”字符) 更新代码 总而言之,您的代码应该进行如下更改: #include <iostream> int main() { int cnt = 0, sum = 0, value = 0; std::cout << "Please enter a set of numbers and then

解释的解决方案

为了计算所提供的整数数量,只要在给出新输入时向cnt添加1即可(见下面带有//**注释的行)

此外,不需要在开始时进行cnt==值检查(其中缺少一个“=”字符)

更新代码

总而言之,您的代码应该进行如下更改:

#include <iostream>
int main()
{
  int cnt = 0, sum = 0, value = 0;
    std::cout << "Please enter a set of numbers and then press ctrl+z and ENTER to add the numbers that you entered" << std::endl;
    if (cnt = value) 
    ++cnt;          
    while (std::cin >> value)

       sum += value;  

    std::cout << "the sum is: " << sum << std::endl;
    std::cout << "the amount of numbers you entered are: " << cnt << std::endl;

    return 0;

}
#包括
int main()
{
int cnt=0,sum=0,value=0;
std::cout值)
{
总和+=数值;
cnt++//**
}

std::您是否需要提供输入和输出案例请阅读。您的标题以非单词和非相关信息开头。您的问题的答案是“是”。(这使它成为一个问得不好的问题)。顺便说一句,您应该启用警告。如果(cnt=value)
,编译器可能会警告
,请参阅
#include <iostream>
int main()
{
    int cnt = 0, sum = 0, value = 0;
    std::cout << "Please enter a set of numbers and then press ctrl+z and ENTER to add the numbers that you entered" << std::endl;      
    while (std::cin >> value)
    {
       sum += value;  
       cnt++; //**
    }
    std::cout << "the sum is: " << sum << std::endl;
    std::cout << "the amount of numbers you entered are: " << cnt << std::endl;

    return 0;

}