Calculations coming up as 0 when i run the program

Ive been wrapping my brain around this all day and i cant find a specific answer to help me, before this i had serious trouble just to get it compiled but thanks to that long drawn out process i understand alot more but this is a different story...

Heres the program, haha as simple as it looks its kinda sad how much trouble it giving me but i digress...

#include<iostream>
using namespace std;

int main()
{
//declare variables

double num1=0.0;
double num2=0.0;
double sum=0.0;
double diff=0.0;
double quo=0.0;
double prod=0.0;

cout<<"enter 1st number:"<<endl;
cin>>num1;
cout<<"enter 2nd number:"<<endl;
cin>>num2;


num1 + num2== sum;
num1 - num2== diff;
num1 / num2== quo;
num1 * num2== prod;


//display

cout<<"The sum is:"<<sum<<endl;
cout<<"The difference is:"<<diff<<endl;
cout<<"The quotient is:"<<quo<<endl;
cout<<"The product is:"<<prod<<endl;

system("pause");
return 0;
}

my problem is when i run it, no matter what i enter all the answers come out as 0's. thanks in advance
Change

1
2
3
4
num1 + num2== sum;
 num1 - num2== diff;
 num1 / num2== quo;
 num1 * num2== prod;


to

1
2
3
4
sum  = num1 + num2;
diff = num1 - num2;
quo  = num1 / num2;
prod = num1 * num2;


Or write your own programming language.:)
Last edited on
1
2
3
4
num1 + num2== sum;
num1 - num2== diff;
num1 / num2== quo;
num1 * num2== prod;

Your problem is this. == is the operator to compare two values (check if they're equal or not), and plus you're doing it backwards. As it is, that whole block doesn't do anything useful at all, and certainly not what you wanted it to do. Do it like this instead, and learn from the example:

1
2
3
4
sum = num1 + num2;
diff = num1 - num2;
quo =  num1 / num2;
prod = num1 * num2;


edit: Lol, beaten to it :P
Last edited on
Topic archived. No new replies allowed.