c++ - Stroustrup's P:PP Chapter 4 Drill: Stuck -


i'm stuck on stroustrup's p:pp chapter 4 drill, part 5. problem asks me write program consists of while-loop reads 2 doubles , terminates program when character | entered. program should output both doubles, tell smaller , larger, , whether or not they're equal or equal. took definition equal when numbers within 0.1 of each other. wrote program terminates when non-double input entered, instead of |.

when input 15.0 , 19.0, i'm still told "the values equal," instead of 15.0 smaller , 19.0 larger. curiously, if input 19.0 , 15.0, tell me smaller value 15, , larger 1 19. if input 15.0 , 15.0, tell me values equal.

basically, if x < y, , input in order "x y" "almost equal," if input "y x" i'm told x smaller , y larger. otherwise, error-free.

any suggestions?

#include "../../../std_lib_facilities.h"  int main() {     double val1 = 0;     double val2 = 0;     cout << "enter 2 values: \n";      while (cin >> val1 >> val2) {          if (val1 < val2) {             cout << "the smaller value " << val1 << " , bigger value " << val2 << '\n';         }         else if (val1 == val2) {             cout << "both values equal.\n";         }         else if (val1 > val2) {             cout << "the smaller value " << val2 << " , bigger value " << val1 << '\n';         }         else (val1 - val2 <= 0.01 && val1 != val2 || val2 - val1 <= 0.01 && val1 != val2) {             cout << "the values equal.\n";         }     }  } 

the problem in order of "if-else" conditions: important because 1 such condition fulfilled, other ones no longer checked.


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

Nuget pack csproj using nuspec -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -