Feb 12, 2019 at 8:24am UTC
my problem was to slove the ecuation (a+b+c)/(a+c)-(1/a)
and my code is
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
#include <iostream>
using namespace std;
int main()
{
int a, b, c, ex;
cout<<"a= " <<endl;
cin>>a;
cout<<"b= " <<endl;
cin>>b;
cout<<"c= " <<endl;
cin>>c;
if ((a==0)or(a+c==0)) cout<<"Ex dosent make sens" <<endl;
else ex==((a+b+c)/(a+c))-(1/a);
cout<<"Value of expresion for a=" <<a<<"b=" <<b<<"c=" <<c<<"is " <<ex<<"." <<endl;
return 0;
}
and my program keep showing me the result is 1951951802
Last edited on Feb 12, 2019 at 8:32am UTC
Feb 12, 2019 at 8:30am UTC
Use = for assigning the value of the expression to the variable.
The == operator is for comparing if two things are equal. It doesn't modify anything.
Feb 12, 2019 at 8:43am UTC
thanks you, but one question... if i insert the value for example a=1
b=1
c=1
after compile and run it show me the vlaue 0... it suposed to show 0,5... what i can do?
Feb 12, 2019 at 9:21am UTC
else ex==((a+b+c)/(a+c))-(1/a);
should be
else ex=((a+b+c)/(a+c))-(1/a);
(which was Peter87's comment.)
Then
int a, b, c, ex;
should be
double a, b, c, ex;
or you will be subject to integer division ( 3/2 gives ... 1 yes, really!)