# How can you fix the limits of a program?

#include<iostream>

#include<conio.h>

using namespace std;

int main(){

cout<<"Digite un numero: "; cin>>numero;

cout<<"Y su exponente: "; cin>>exponente;

if(numero<0){

getch(); return 0;

}

if(exponente==0){

cout<<"El resultado es 1"<<endl; getch(); return 0;

}

if(exponente==1){

cout<<"El resultado es "<<numero<<endl; getch(); return 0;

}

while(exponente>2){

exponente--;

}

}

getch();

return 0;

}

What you saw is my program, and it works! But it has limits, the program breaks off if your numbers are too big. How can you fix this?

answered Dec 3, 2019 by anonymous
English

You a using int (it is used for small numbers), try to use float, double or long long int

Portuguese:

Voce está usando o tipo int (esse tipo eh usado em variaveis não tão grandes), tente usar o tipo float, double ou long long int

#include <iostream>

#include<conio.h>

using namespace std;

int main(){

cout<<"Digite un numero: "; cin>>numero;

cout<<"Y su exponente: "; cin>>exponente;

if(numero<0){

getch(); return 0;

}

if(exponente==0){

cout<<"El resultado es 1"<<endl; getch(); return 0;

}

if(exponente==1){

cout<<"El resultado es "<<numero<<endl; getch(); return 0;

}

while(exponente>2){

exponente--;

}

}

getch();

return 0;

}
answered Dec 3, 2019 by (2,950 points)

Your variables have type of int (integer). This type, as every other type has a range of numbers that it can represent. While this range is quite high for integer, it is not infinite. To be exact the range is -32,768 to 32,767 on 32-bit systems or -2,147,483,648 to 2,147,483,647 on 64-bit system.

What it means is your "resultado" variable gets so big that it can't be displayed correctly anymore. It got out of the range of integer.

You might want to use a type with bigger range, such as double: