2017-07-11 10 views
-1

私のコードで何が間違っているのか分かりません。私は、挨拶メッセージが表示される関数と、単純な計算が行われる他の関数の2つの関数を作成しました。関数は1つの引数を取らない

#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つの引数

+1

は 'Total'は、2つの引数を取り、あなたが唯一の – MotKohn

+0

がエラーに関連していない供給しているが、主な'の内側:

あなたはこれを実行する必要があります'、' void greetings(); 'は単に' greetings(); 'でなければなりません。 –

答えて

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

を負いません。合計は2つの引数をとりますが、上記の行では1つの引数しか渡していません。 )(

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

そして

int total(int, int); 
+0

エラーメッセージC2660: 'total':関数が2つの引数を取らない – user8286839

+2

@ user8286839ソースファイルの先頭にある関数プロトタイプが間違っています。実際の関数定義と一致させるには 'int total(int、int);'でなければなりません。 – Blastfurnace

+0

はい。これを行う^。私は私の答えを更新します。 – Ani

関連する問題