Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/136.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/security/4.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++ 为什么不打印void函数的编码?_C++ - Fatal编程技术网

C++ 为什么不打印void函数的编码?

C++ 为什么不打印void函数的编码?,c++,C++,能帮我解释一下我哪里弄错了吗? 我只是不知道我错在哪里;C void largest(int); void smallest(int); void average(double); int main() { int n=0,i=1,num,max=0,min=0,sum=0; double avg=0; cout<<"Please enter total number of integers: "; cin>>

能帮我解释一下我哪里弄错了吗? 我只是不知道我错在哪里;C

void largest(int);
void smallest(int);
void average(double);

int main()
{
    int n=0,i=1,num,max=0,min=0,sum=0;
    double avg=0;
    
    cout<<"Please enter total number of integers: ";
    cin>>n;
    cout<<"\n";
    
    while (n>0)
    {
        cout<<"Enter integer "<<i<<": ";
        cin>>num;
        
        if (num>max)
        max=num;
        
        if (num<min)
        min=num;
        
        sum=sum+num;
        
        n--;
        i++;
    }
    
    avg=sum/n;
    
    largest(max);
    smallest(min);
    average(avg);
    
    return 0;
}
void largest(int max)
{
    cout<<"The largest integer is: "<<max;
}

void smallest(int min)
{
    cout<<"The smallest integer is: "<<min;
}

void average(double avg)
{
    cout<<"The average is: "<<avg;
}
void最大值(int);
无效最小值(int);
无效平均值(双倍);
int main()
{
int n=0,i=1,num,max=0,min=0,sum=0;
双平均值=0;
coutn;

cout您正在除以0,因为您正在修改n,直到它达到0,然后使用它进行除法,最好使用另一个变量进行迭代,而不是减少n的值。所以问题不是它没有打印,而是程序在达到该值之前就死了

进程已退出…返回值为322225620

322125620是状态整数除以零(0xC0000094)异常的数字代码,这意味着您的代码在有机会打印其消息之前崩溃

在这一行:

avg=sum/n;
n
此时为0,因为它上面的
while
循环在每次迭代中都会减小
n
,直到
n
达到0

为了避免这种情况,请将
while
循环更改为不再修改
n


while(我也知道你在做整数数学。结果将是一个整数,即使你把它放在一个double中。你需要用sum除以i,而不是n@vikram实际上
i-1
因为
i
被初始化为1,所以在第一次迭代后将是2,etc@RemyLebeau右:)您需要在每行末尾打印换行符“\n”。可能需要提及
sum/n
@chux的非
double
结果。是的,这是代码存在的另一个问题。但手头的问题是代码为什么根本不打印消息。而不是它为什么打印错误的结果。这将是一个di没关系的问题。我已经改正了我的错误,谢谢你:这对我帮助很大。