Ask your own question, for FREE!
Computer Science 12 Online
OpenStudy (anonymous):

can someone help me im getting some errors void addBig(int a[], int b[], int c[]) { int i, temp, ones, carry; for(i=0;i<=MAX_DIGITS-1;i++)//sets the int c[] to zero c[i]=0; for(i=0;i<=MAX_DIGITS-1;i++) { c[i]=a[i]+b[i];//adds the arrays togther } for(i=0;i<=MAX_DIGITS-1;i++) { ones=c[i]%10; carry=c[i]/10; c=carry[i]; c=ones + carry c[i+1] } }

OpenStudy (anonymous):

the last two lines are giving me errors c=carry{i} and c=ones+carry c{i+1}

OpenStudy (konradzuse):

where us max_digits?

OpenStudy (konradzuse):

carry[] doesn't exist from whatr I see

OpenStudy (konradzuse):

c by itself also doesn't exist... You cannot get rid of an array, or add them randomly.. c != c[] carry != carry[]

OpenStudy (anonymous):

well this is the whole code //harjasdeep Samra //This program will test three functions capable of reading, adding, and printing 100-digit numbers. #include <iostream> #include<string> using namespace std; // Do not change these function prototypes: void readBig(int[]); void printBig(int[]); void addBig(int[], int[], int[]); // This constant should be 100 when the program is finished. const int MAX_DIGITS = 100; //There should be no changes made to the main program when you turn it in. int main() { // Declare the three numbers, the first, second and the sum: int num1[MAX_DIGITS], num2[MAX_DIGITS], sum[MAX_DIGITS]; bool done = false; char response; while (!done) { cout << "Please enter a number up to "<<MAX_DIGITS<< " digits: "; readBig(num1); cout << "Please enter a number up to "<<MAX_DIGITS<< " digits: "; readBig(num2); addBig(num1, num2, sum); printBig(num1); cout << "\n+\n"; printBig(num2); cout << "\n=\n"; printBig(sum); cout << "\n"; cout <<"test again?"; cin>>response; cin.ignore(900,'\n'); done = toupper(response)=='N'; } return 0; } //ReadBig will read a number as a string, //It then converts each element of the string to an integer and stores it in an integer array. //Finally, it reverses the elements of the array so that the ones digit is in element zero, //the tens digit is in element 1, the hundreds digit is in element 2, etc. void readBig(int x[]) { int length, i, oneLess, l; string number; getline(cin,number); length=number.length(); l=length-1; oneLess=MAX_DIGITS-1; for(i=0;i<MAX_DIGITS;i++) { x[i]=0; } for(i=0;i<=length-1;i++) { x[i]=number.at(l)-'0'; l--; } } //PrintBig uses a while loop to skip leading zeros and then uses a for loop to print the number. void printBig(int a[]) { int count, i=0; bool x=true; count=MAX_DIGITS-1; while(x) { if(a[count]!=0) x=false; //else if(count==MAX_DIGITS-1) //x=false; else //i++; count--; } for(i=count;i>=0;i--) cout<<a[i]; } //AddBig adds the corresponding digits of the first two arrays and stores the answer in the third. //In a second loop, it performs the carry operation. void addBig(int a[], int b[], int c[]) { int i, temp, ones, carry; for(i=0;i<=MAX_DIGITS-1;i++)//sets the int c[] to zero c[i]=0; for(i=0;i<=MAX_DIGITS-1;i++) { c[i]=a[i]+b[i];//adds the arrays togther } for(i=0;i<=MAX_DIGITS-1;i++) { ones=c[i]%10; carry=c[i]/10; c=carry[i]; c=ones + carry c[i+1] } }

OpenStudy (konradzuse):

same error as stated above.

OpenStudy (anonymous):

yes

OpenStudy (konradzuse):

"KonradZuse c by itself also doesn't exist... You cannot get rid of an array, or add them randomly.. c != c[] carry != carry[] 8 minutes ago"

OpenStudy (anonymous):

how could i fix this problem

OpenStudy (konradzuse):

Not sure exactly what each variable is doing, but if you need a carry array then make it an array, and if you need a single variable 'c' then make it a dummy variable since you use it once... You also seem to only use carry once, so I'm not sure why there is an array of it.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!