This program is supposed to return the lowest number of three inputted double, floating numbers. But it always returns -1.#IND.
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#pragma once
#include "targetver.h"
#include <stdio.h>
#include <tchar.h>
#include <iostream>
using std::cin;
using std::cout;
// TODO: reference additional headers your program requires here
// exercise6-28.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
double smallest (double, double, double);
int _tmain(int argc, _TCHAR* argv[])
{
double a;
double b;
double c;
cout<<"Enter three double-precision #s";
cin>> a>>b>>c;
cout<<"The smallest number is "<<smallest (a, b,c);
cin>>a;
return 0;
}
double smallest (double a, double b, double c){
if (a>b>c)
return c;
if (b>c>a)
return a;
if (c>a>b)
return b;
}
Relational operators are evaluated left-to-right. Therefore, a>b>c is equivalent to (a>b) > c, where you compare a boolean (result of a>b) to a double (c). You are unlucky, if that gives an expected answer.