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

#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();是为什么呀

慕雪6442864
浏览 673回答 1
1回答

慕勒3428872

因为你的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;}}
打开App,查看更多内容
随时随地看视频慕课网APP