Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

Jas11

  • 3 years ago

i'm getting errors in my program and need help error C2109: subscript requires array or pointer type error C2440: '=' : cannot convert from 'int' to 'int []' error C2146: syntax error : missing ';' before identifier 'c'

  • This Question is Closed
  1. Jas11
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    this is my program the error is from the last function //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]; } }

  2. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy