error: too many arguments to function 'int rand0_toN1()'
error: too many arguments to function 'int rand0_toN1()'
我无法理解这个问题,我正在尝试学习 c++,但我以前从未遇到过这个错误,关于此类错误的其他答案对于我的水平来说太高级了,我无法遵循
我在 windows 10
上使用代码块 20.03
#include <iostream>
#include <math.h>
#include <iomanip>
#include <stdlib.h>
#include <time.h>
using namespace std;
int rand0_toN1();
void draw_a_card();
char *suits[4]={"Hearts", "Diamonds", "Spades", "Clubs"};
char *ranks[13]={"ace", "two", "three", "four", "five", "six", "seven", "eyght", "nine", "ten",
"jack", "queen", "king"};
int main(){
int n, i;
srand(time(NULL));
while(1){
cout<<"Enter nr. of draws (0 to exit): ";
cin>>n;
if (n==0)
break;
for(i=1; i<=n; i++)
draw_a_card();
}
return 0;
}
void draw_a_card(){
int r,s;
r=rand0_toN1(13);
s=rand0_toN1(4);
cout<<ranks[r]<<" of "<<suits[s]<<endl;
}
int rand0_toN1(int n){
return rand() % n;
}
您声明时没有参数
int rand0_toN1(); // Add parameter here
您的定义有一个参数
int rand0_toN1(int n){
return rand() % n;
}
我无法理解这个问题,我正在尝试学习 c++,但我以前从未遇到过这个错误,关于此类错误的其他答案对于我的水平来说太高级了,我无法遵循
我在 windows 10
上使用代码块 20.03#include <iostream>
#include <math.h>
#include <iomanip>
#include <stdlib.h>
#include <time.h>
using namespace std;
int rand0_toN1();
void draw_a_card();
char *suits[4]={"Hearts", "Diamonds", "Spades", "Clubs"};
char *ranks[13]={"ace", "two", "three", "four", "five", "six", "seven", "eyght", "nine", "ten",
"jack", "queen", "king"};
int main(){
int n, i;
srand(time(NULL));
while(1){
cout<<"Enter nr. of draws (0 to exit): ";
cin>>n;
if (n==0)
break;
for(i=1; i<=n; i++)
draw_a_card();
}
return 0;
}
void draw_a_card(){
int r,s;
r=rand0_toN1(13);
s=rand0_toN1(4);
cout<<ranks[r]<<" of "<<suits[s]<<endl;
}
int rand0_toN1(int n){
return rand() % n;
}
您声明时没有参数
int rand0_toN1(); // Add parameter here
您的定义有一个参数
int rand0_toN1(int n){
return rand() % n;
}