为了账号安全,请及时绑定邮箱和手机立即绑定

为什么运行不了这个C++程序

为什么运行不了这个C++程序

C++
慕雪6442864 2018-07-29 00:00:56
#include<iostream>#include<iomanip>#include<ctime>#include<cstdlib>using namespace std;void cx(int a,int c,int d,int b,int x,int a1,int c1,int d1,int f,bool y){a=rand()%a1;c=rand()%c1;d=rand()%d1;x=0;f=0;y=true;cout<<"Hello!Please play.^v^"<<endl;cout<<a-c<<"~"<<a+d<<endl;while(y){a1+=10;c1+=10;d1+=10;cin>>b;x++;if(b==a){cout<<"Yes!"<<endl<<"You win";f++;return;}if(x==10){cout<<"You lost!"<<endl;f--;return;}if(b<a)cout<<"small"<<endl;if(b>a)cout<<"big"<<endl;} }int main(){srand(time(NULL));int a,b,c,d,x=0,a1=1000,d1=100,c1=100,f=0;bool y=true;for(int i=0;i<10;i++){cx();cout<<f;} }就是上面的,他还显示error: too few arguments to function 'void cx(int, int, int, int, int, int, int, int, int, bool)'cx();是为什么呀
查看完整描述

1 回答

?
慕勒3428872

TA贡献1848条经验 获得超6个赞

因为你的cx函数,声明的时候是带了参数的,你在调用的时候,没带参数,所以报错了。
void cx(int a=0,int c=0,int d=0,int b=0,int x=0,int a1=0,int c1=0,int d1=0,int f=0,bool y=false),你想这样调用的时候,可以加上默认参数。
#include<iostream>
#include<iomanip>
#include<ctime>
#include<cstdlib>
using namespace std;
void cx(int a = 0, int c = 0, int d = 0, int b = 0, int x = 0, int a1 = 0, int c1 = 0, int d1 = 0, int f = 0, bool y = false)
{
a = rand() % a1; c = rand() % c1; d = rand() % d1; x = 0; f = 0; y = true;
cout << "Hello!Please play.^v^" << endl;
cout << a - c << "~" << a + d << endl;
while (y)
{
a1 += 10;
c1 += 10;
d1 += 10;
cin >> b;
x++;
if (b == a){ cout << "Yes!" << endl << "You win"; f++; return; }
if (x == 10){ cout << "You lost!" << endl; f--; return; }
if (b<a)cout << "small" << endl;
if (b>a)cout << "big" << endl;
}
}
int main()
{
srand(time(NULL));
int a, b, c, d, x = 0, a1 = 1000, d1 = 100, c1 = 100, f = 0;
bool y = true;
for (int i = 0; i<10; i++)
{
cx();
cout << f;
}
}

查看完整回答
反对 回复 2018-09-15
  • 1 回答
  • 0 关注
  • 671 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信