c++ - 错误:函数“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;
}
解决方案
您已声明没有参数
int rand0_toN1(); // Add parameter here
您的定义有一个参数
int rand0_toN1(int n){
return rand() % n;
}
推荐阅读
- c# - 在连接服务器上的do目录期间设置超时
- java - 如何在 Java 中反转数组
- vhdl - Using DCM Locked output in Spartan 3 FPGA
- c++ - 使用 Opencv 将姿势值实时写入文本文件
- python - python msrestazure 包抛出隧道连接失败错误
- c# - 将工作流构建到现有应用程序中
- java - Spring Boot Test:根据活动配置文件在测试中执行不同的 sql 脚本?
- asp.net-mvc - 如何验证来自 MVC 表单的重复发布请求
- angular - Angular 组件 styleUrls
- html - 使用 :has()从锚链接中删除下划线或被锚链接包裹