How to find the biggest difference between two numbers using for loop

Hello, I need help with my C++ code. Specifically this part below. I'll need to enter 3 numbers, for example, 49.96, 49.87, 49.80 and I need to find the biggest difference between two of those numbers. The answer is 0.09 as the biggest difference is between 49.96 and 49.87 (49.96-49.87). But how do I find this number using coding? Sorry if there's not enough info, if you need more information, let me know, I'll add more.


for(i=1; i<=3; i++)
{
cin >> kl;
}
49.96 - 49.80 == 0.16

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <cmath>
#include <algorithm>

int main()
{
    double a, b, c ;
    std::cout << "enter three numbers: " ;
    std::cin >> a >> b >> c ;

    // the absolute difference between a and b is std::abs(a-b) etc.
    // http://en.cppreference.com/w/cpp/algorithm/max
    std::cout << "\nthe biggest difference betwen two of these numbers is: "
              << std::max( { std::abs(a-b), std::abs(b-c), std::abs(c-a) } ) << '\n' ;
}

http://coliru.stacked-crooked.com/a/07f4016c318518b2
Topic archived. No new replies allowed.