注册 登录
编程论坛 C++教室

这段语句哪里错了,运行总报错

angle2023 发布于 2023-03-13 21:59, 110 次点击
#include "stdafx.h"
#include<iostream>
using namespace std;
int main(int argc, char *argv[])
{ float sum(float a=8,float b=10,float c=3);
  float a,b,c;
  cin>>a,b,c;
  cout<<sum(a)<<sum(a,b)<<sum(a,b,c)<<endl;
  return 0;
}
float sum(float a,float b,float c)
{
return a+b+c;
}


[此贴子已经被作者于2023-3-13 22:06编辑过]

2 回复
#2
rjsp2023-03-14 10:11
程序代码:
#include <iostream>
using namespace std;

float sum( float a=8, float b=10, float c=3 );

int main( void )
{
    float a, b, c;
    cin >> a >> b >> c;
    if( !cin )
    {
        cerr << "输错了.\n";
        return 1;
    }

    cout << sum(a) << '\n'
         << sum(a, b) << '\n'
         << sum(a,b,c) << endl;
}

float sum( float a, float b, float c )
{
    return a+b+c;
}
#3
angle20232023-03-14 14:25
回复 2楼 rjsp
搞明白了,谢谢!
程序代码:
#include "stdafx.h"
#include<iostream>
using namespace std;
int main()
{ float sum(float a=8,float b=10,float c=3);
  float a,b,c;
  cin>>a>>b>>c;
  cout<<sum(a)<<","<<sum(a,b)<<","sum(a,b,c);
  return 0;
}
float sum(float a,float b,float c)
{
return a+b+c;
}

1