Functions

I am a bit confused in functions maybe because I am teaching myself but can any
one tell me how to write a code in which you have to input a number until the difference between two recent numbers is equal to 10. Thank you
1
2
3
4
5
6
7
8
9
10
11
12
13
#include<cmath>

int num1, num2;
do
{
    cout << "Enter number 1 : "; cin >> num1;
    cout << "Enter number 2 : "; cin >> num2;

    if(abs(num1 - num2) != 0)
    {
         cout << "The difference between two numbers are not exactly 10!\n\n";
    } else break;
}while(true);
Thank you but I think I didn't made this clear in my question but the actual code is that we have to input numbers continuously until the difference between the two latest numbers entered is 10. For example if the user enters these inputs 2, 4, 7, -3 and -15 then the output will say that the difference between -3 and -15 is greater then or equal to 10. Thank you for the reply though.
It would be easier if you show us the code of what have you done so far. Then, we can give you some pointers on how to solve it.
I don't know how to code it but this is the sample output maybe this will give an idea what I am talking about.

Sample input and output when 2, 4, 7, -3 and -15 are input:

Enter some integers:
2
4
7
-3
-15
The difference between -3 and -15 is greater than or equal to 10.
This is the start of my program now I need to write the codes in 'Diff' function which is going to determine that when the difference between the two recent entered numbers is 10. I am sorry I am just a beginner.

#include <iostream>
#include<cmath>
using namespace std;
int Diff(int num1);
int main()
{
int sum = 0;
int input;

for (int i = 0; i != 10; ++i)
{
cout << "Enter a number " << endl;
cin >> input;

sum += input;
}

return 0;
}
int Diff(int num1)
{

return 0;
}
Last edited on
I have the same problem but no one here is telling me what to do.. :(
Topic archived. No new replies allowed.