1 回答
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;
}
}
- 1 回答
- 0 关注
- 671 浏览
添加回答
举报