Writing a program help

Instructions:Write a program that reads two numbers and stores them into variables double x,y; Then the code finds the values of the sum and difference of the two numbers and stores them in double sum, diff; Then the code determines whether the sum is larger/equal/smaller than difference.

#include <iostream>
using namespace std;

int main() {

double x, y, sum , diff;
cout << "Tell me the value of x."<<endl;
cin >> x;
cout << "Tell me the value of y."<<endl;
cin >> y;

sum = x + y;
diff = x - y;

I got this so far and im stuck
im not sure how to store the sum and diff in the double sum, diff;
and how to do "Then the code determines whether the sum is larger/equal/smaller than difference."
please help thank you.

so far your code is just right,

Use if - else if - else statements for your problem:

1
2
3
4
5
6
7
8
9
10
11
12
if ( sum == diff ) // if sum is equal to diff
{
    cout << "Equal" << endl;
}
else if ( sum < diff ) // if sum is less than diff
{
     cout << "Sum if less smaller than the diff" << endl;
}
else if ( sum > diff ) // if sum is greater than diff
{
    /* bla bla bla */
}


For further info look at this link about control structures:
http://www.cplusplus.com/doc/tutorial/control/
Topic archived. No new replies allowed.