[Solved] Please guide me, my program is not working and showing error id return 1 exit status


I compiled your code using g++ and then run the binary. Result shown below:

Enter first number: 10
Enter second number: 20
30Addition is: 0

I did not get an error when executing the binary however, like others have already pointed out, there is one error in your code. I guess your intention was to store the sum in variable “add”. To do that you need this line of code before you print add:

add = addition(num1, num2);

But your function addition returns a void, this needs to be changed to return an int as shown below:

int addition(int, int);

The function body can be like shown below:

int addition(int a, int b){return a+b;}

A suggested rewrite of your code:

#include <iostream>
using namespace std;

int addition(const int& a, const int& b){return a+b;}

int main()
{
    int num1{};
    int num2{};

    cout<<"Enter first number: ";
    cin>>num1;

    cout<<"Enter second number: ";
    cin>>num2;

    int&& add = addition(num1,num2);
    cout<<"Addition is: "<<add<<endl;

    return 0;
}

compile the code using g++ -std=c++11

3

solved Please guide me, my program is not working and showing error id return 1 exit status