C++ error

+3 ♦Avishka RJ ♦™ · January 14, 2015
I wrote below code according to bucky's tutorial. but it dosent work. whats the wrong with it??

#include <iostream>
using namespace std;

void addnumbers(int x,int y){

    int answer = x + y;
    return answer ;
}

int main(){
    cout << addnumbers(10,20);
    return 0;
}

error massage is 


  • E:\Programming\C++\fuctions (more)\main.cpp|11|error: no match for 'operator<<' in 'std::cout << addnumbers(10, 20)'|


Post a Reply

Replies

Oldest  Newest  Rating
+1 Laura Lee · January 14, 2015
The addnumbers function is meant to return a value to the user. An int value to be precise.
Your function is void. Meaning it does not return anything. Change it to int.

int addnumbers(int x, int y)
{
return x+y;
}
  • 1

C++

107,319 followers
About

Used in many types of software including music players, video games, and many large scale applications.

Links
Moderators
Bucky Roberts Administrator