首页 > 解决方案 > 错误:函数“int rand0_toN1()”的参数太多

问题描述

我无法理解这个问题,我正在尝试学习 c++,但我以前从未遇到过这个错误,关于这种类型的错误的其他答案对于我的水平来说太高级了,我无法遵循

我在 Windows 10 上使用 Code Blocks 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;
}

标签: c++codeblocks

解决方案


您已声明没有参数

int rand0_toN1(); // Add parameter here

您的定义有一个参数

int rand0_toN1(int n){
    return rand() % n;
}

推荐阅读