Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- 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
- usar la función pow.
- b) Implemente una función que verifique si un carácter introducido es un número o no.
- Ninguna de las dos funciones anteriores debe pedir datos al
- usuario o imprimir información en la pantalla.
- c) Dentro de la función main(), pida al usuario los valores que
- correspondan y llame a la función. */
- #include <iostream>
- #include <cstdlib>
- #include "Helper.h"
- using namespace std;
- //////////////////////////////////////////////////////////////////
- int validateInteger(string);
- int elevar(int, int );
- //////////////////////////////////////////////////////////////////
- int main (){
- int X = validateInteger("\n\n > INGRESE UN NUMERO: ");
- int Y = validateInteger("\n > INGRESE UN NUMERO: ");
- cout<<"\n\t////// NUMEROS CARGADAOS //////\n"<<endl;
- cout<<"\n\t > NUMERO X: "<<X<<endl;
- cout<<"\n\t > NUMERO Y: "<<Y<<endl;
- int poten;
- poten = elevar(X,Y);
- cout<<"\n\t > POTENCIA DE: "<<poten;
- return 0;
- }
- //////////////////////////////////////////////////////////////////
- int validateInteger(string mensaje){
- int entero;
- do{
- cout<<mensaje;
- cin>>entero;
- if(cin.fail()==true){
- cin.clear();
- cin.ignore(100,'\n');
- cout<<"\n\t #ERRO: INGRESE UN NUMERO ENTERO\n\n"<<endl;
- continue;
- }
- else{break;}
- }while(true);
- return entero;
- }
- //////////////////////////////////////////////////////////////////
- int elevar(int X, int Y){
- int potencia=1;
- for(int i=1; i<=Y; i++){
- potencia *= X;
- }
- return potencia;
- }
Add Comment
Please, Sign In to add comment