函数不接受 1 个参数

function does not take 1 arguments

本文关键字:参数 不接受 函数      更新时间:2023-10-16

我不知道我的代码出了什么问题。我创建了两个函数,一个显示问候消息,另一个函数完成简单的计算。

#include "stdafx.h"
#include <iostream>
#include <Windows.h>
using namespace std;
void greetings();
int total();
int main()
{
void greetings();
int num1, num2, sum;
cout<<"Enter a number to calculate : ";
cin>>num1;
cout<<"Enter another number to add : ";
cin>>num2;
sum = num1 + num2;
cout<<"The total number is "<<total(sum)<<endl;
system("PAUSE");
return 0;
}
/*Every function is down here*/
void greetings(){
cout<<"Welcome to the function 5"<<endl;
cout<<"Here we will try to call many function as possible"<<endl;
}
int total(int a, int b){
return a + b;
}

我收到此错误消息:

函数不接受 1 个参数

cout<<"The total number is "<<total(sum)<<endl;

这是你的问题。Total 需要 2 个参数,但在上行中您只传递一个参数。

您需要这样做:

sum = total(num1, num2);
cout<<"The total number is "<<sum<<endl;

int total(int, int);