简体   繁体   中英

function does not take 1 arguments

I don't know what is wrong with my code. I created two functions, one in which the greetings message is displayed, and in the other function a simple calculation is done.

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

I get this error message:

function does not take 1 arguments

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

This is your problem. Total takes 2 arguments but in the above line you are only passing one argument.

You need to do this:

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

And

int total(int, int);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM