error: assignment of function

Hi.Im new to programming .
I started learning c++ few days ago.i chose my first book Jumping into c++ by alex allain.
At the end of chapter 6 there are some practice problems.
This is the one
Make your calculator program perform computations in a separate function for each type of computation.
Why is does not let me asign ?
im doing the rest of the problem in the right way?
|48|error: assignment of function 'int adunare(double, double)'|
|48|error: cannot convert 'double' to 'int(double, double)' in assignment|

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
 #include <iostream>
#include <string>

using namespace std;
int add(double nr1 , double nr2);
int substraction(double nr1, double nr2);
int multiply(double nr1,double nr2);
int divide(double nr1,double nr2);


int main ()
{
double nr1 ;
double nr2 ;
double rezultat ;
string operatia_dorita ;
cout << "Enter the first number:\n" ;
cin >> nr1 ;
cout << "Enter second number:\n" ;
cin >> nr2 ;
cout << "Enter the operation:\n" ;
cin >> operatia_dorita ;
if(operatia_dorita == "+")
     {
         cout << "rezultatul la primu numar + doilea numar este:  "   ;
         return add(nr1,nr2);
     }
else if(operatia_dorita == "-")
     {

        cout << "rezultatul la primu numar - doilea numar este: "  ;
        return substraction(nr1,nr2);
     }
else if(operatia_dorita == "*")
    {
        cout << "rezultat la inmultirea dumneavoastra este :\n";
        return multiply(nr1,nr2);
    }
else if (operatia_dorita == "/")
    {
        cout << "rezultatul la impartirea dumneavoastra este:\n";
        return divide(nr1,nr2);
    }
}

int add(double nr1, double nr2)
{
    add = nr1 + nr2;
}

int substraction(double nr1,double nr2)
{
    substraction = nr1 - nr2;
}
int multiply(double nr1,double nr2)
{
     multiply = nr1 * nr2;
}

int divide(double nr1,double nr2)
{
    divide = nr1/nr2;
}
add = nr1 + nr2;
Did you learn Pascal before? In C and C++ to return result of a function you use return statement:
return nr1 + nr2;
MiiNiPaa thank you very much!
i didnt learn pascal before but i wish i did..i really want to learn programming
i did some changes after you told me how to return and it works fine thank you again.
#include <iostream>
#include <string>

using namespace std;
int adunare(double nr1 , double nr2);
int scadere(double nr1, double nr2);
int inmultire(double nr1,double nr2);
int impartire(double nr1,double nr2);


int main ()
{
double nr1 ;
double nr2;
double rezultat;
string operatia_dorita;
cout << "introduceti primul numar:\n";
cin >> nr1;
cout << "introduceti al 2 lea numar:\n";
cin >> nr2;
cout << "introduceti operatia dorita:\n";
cin >> operatia_dorita;
if(operatia_dorita == "+")
{

cout << "rezultatul la primu numar + doilea numar este: " ;
return nr1 + nr2;
}
else if(operatia_dorita == "-")
{

cout << "rezultatul la primu numar - doilea numar este: " ;
return nr1 - nr2;
}
else if(operatia_dorita == "*")
{

cout << "rezultat la inmultirea dumneavoastra este :\n";
return nr1 * nr2;
}
else if (operatia_dorita == "/")
{

cout << "rezultatul la impartirea dumneavoastra este:\n";
return nr1 / nr2;
}
}
Topic archived. No new replies allowed.