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 %26lt;iostream%26gt;
#include %26lt;iomanip%26gt;
using namespace std;
int main()
{
int augent[20];
int index;
for(index = 0; index %26lt;20; index++)
{
augent [index]=0.0;
cout%26lt;%26lt;"Please enter augent: ";
cin%26gt;%26gt;augent[index];
cout%26lt;%26lt;endl;
cout%26lt;%26lt;"Augent is "%26lt;%26lt;augent[index]%26lt;%26lt;endl;
}
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.
C++ Arrays?
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))
Reply: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.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment