mendoza_franco

CLASE02 - #PRACTICA04

Sep 19th, 2021 (edited)
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.64 KB | None | 0 0
  1. /*
  2. a)  Implemente una función f(x) que tome por parámetro dos números x, y (entero) y devuelva el resultado de xy, no
  3.     usar la función pow.
  4.  
  5. b)  Implemente una función que verifique si un carácter   introducido es un número o no.
  6.     Ninguna de las dos funciones anteriores debe pedir datos al
  7.     usuario o imprimir información en la pantalla.
  8.  
  9. c)  Dentro de la función main(), pida al usuario los valores que
  10.     correspondan y llame a la función.     */
  11. #include <iostream>
  12. #include <cstdlib>
  13. #include "Helper.h"
  14. using namespace std;
  15. //////////////////////////////////////////////////////////////////
  16. int validateInteger(string);
  17. int elevar(int, int );
  18. //////////////////////////////////////////////////////////////////
  19. int main (){
  20.         int X = validateInteger("\n\n > INGRESE UN NUMERO: ");
  21.         int Y = validateInteger("\n > INGRESE UN NUMERO: ");
  22.        
  23.             cout<<"\n\t//////  NUMEROS CARGADAOS  //////\n"<<endl;
  24.             cout<<"\n\t > NUMERO X: "<<X<<endl;
  25.             cout<<"\n\t > NUMERO Y: "<<Y<<endl;
  26.         int poten;     
  27.         poten = elevar(X,Y);
  28.         cout<<"\n\t > POTENCIA DE: "<<poten;
  29.     return 0;
  30. }
  31. //////////////////////////////////////////////////////////////////
  32.     int validateInteger(string mensaje){
  33.         int entero;
  34.             do{
  35.                 cout<<mensaje;
  36.                     cin>>entero;
  37.                 if(cin.fail()==true){
  38.                     cin.clear();
  39.                         cin.ignore(100,'\n');
  40.                             cout<<"\n\t #ERRO: INGRESE UN NUMERO ENTERO\n\n"<<endl;
  41.                     continue;
  42.                 }
  43.                 else{break;}
  44.             }while(true);  
  45.         return entero;
  46.     }
  47. //////////////////////////////////////////////////////////////////
  48. int elevar(int X, int Y){
  49.  int potencia=1;
  50.  
  51.  for(int i=1; i<=Y; i++){
  52.   potencia *= X;
  53.   }
  54.  
  55.  return potencia;
  56. }
Add Comment
Please, Sign In to add comment