簡體   English   中英

函數不帶1個參數

[英]function does not take 1 arguments

我不知道我的代碼有什么問題。 我創建了兩個函數,一個函數顯示問候消息,另一個函數進行簡單的計算。

#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;

這是你的問題。 總計有2個參數,但在上一行中,您僅傳遞了一個參數。

您需要這樣做:

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

int total(int, int);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM