English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories
0

i have to make a c++ program using arrays, that adds 2 integers up to 20 characters long. right now, i'm stuck before i even started because my array only outputs correctly if the input number is 10 characters long. what's wrong with this?

#include
#include

using namespace std;

int main()
{
int augent[20];
int index;

for(index = 0; index <20; index++)
{
augent [index]=0.0;
cout<<"Please enter augent: ";
cin>>augent[index];
cout< cout<<"Augent is "< }
return 0;
}


Also, once this problem is solved how do i proceed with the rest of the program?

Also I ve been told I have to use strings, is that true?

I would greatly appreciate your help.

2006-10-18 06:14:37 · 2 answers · asked by me_26_07 1 in Computers & Internet Programming & Design

2 answers

Type | Bytes | range of values
-------------------------------------------------------------------------------
int 4 –2,147,483,648 to 2,147,483,647

unsigned int 4 0 to 4,294,967,295
-------------------------------------------------------------------------------

main problem is that you CANT have a 20 digit INT, what u need is either a __int64 (long long) or an unsigned __int64 (unsigned long long) these allow –9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 and 0 to 18,446,744,073,709,551,615 respectivly as they are 8 byte,

that or choose another way to store them (maybe as a text value, as there is a c++ function to convert btw text and numbers (or just write your own))

2006-10-18 06:29:06 · answer #1 · answered by icelotuskun 3 · 0 0

integers have a range which they work in I think 20 characters
eg 100000000000000000000 is out of the range of an integer. Try floats I am not sure how much they hold or use strings then convert them into ints.

Also why does your array have 20 elements isnt it suposed to be 2 elements 20 char long each? maybe i dont get the question.

2006-10-18 06:22:50 · answer #2 · answered by tru_story 4 · 0 0

fedest.com, questions and answers