Advertisement
AntonioVillanueva

Compara dos numeros

Jul 17th, 2015
343
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.77 KB | None | 0 0
  1. // compilacion->     g++ -std=c++11 -o test test.cpp
  2. #include <iostream>
  3. using namespace std;
  4. //----------------------------------------------------------------------
  5. int ComparaNumeros(float a,float b){
  6.     if ((a-b)==0) {return 0;}// 0 ,Igual ==
  7.     if ((a-b)<0){return -1;}// -1 , a menor a b
  8.     return (1);//               1  ,a es mayor que b
  9. };
  10. //----------------------------------------------------------------------
  11. int main(){
  12.     float a,b;
  13.         while (1){//Bucle de test infinito ....
  14.            
  15.     cout <<endl;
  16.     cout << "Primer num a=";cin >>a;
  17.     cout << "Segundo num b=";cin >>b;
  18.    
  19.     switch (ComparaNumeros(a,b)){//Test de la funcion ComparaNumeros
  20.         case 0: cout <<"Igual"<<endl;break;
  21.         case 1 :cout <<"a > b"<<endl;break;
  22.         default :cout <<"a < b"<<endl;break;
  23.     }  
  24. }
  25.     return 0;
  26. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement