Rahul Patil

Rahul Patil

  • 1.6k
  • 183
  • 30.8k

Invalid type[int][int] for array subscript in c++?

Feb 26 2020 10:53 AM
I m new in c++ how to solve error:
 
  1. main.cpp: In function ‘int main()’:  
  2. main.cpp:25:47: error: invalid types ‘int[int]’ for array subscript  
  3. result[size]=add(num1[size],num2[size]);  
  4. ^  
  5. main.cpp:25:58: error: invalid types ‘int[int]’ for array subscript  
  6. result[size]=add(num1[size],num2[size]);  
  7. ^  
  8. main.cpp:25:59: error: ‘add’ was not declared in this scope  
  9. result[size]=add(num1[size],num2[size]);  
  10. ^  
  11. main.cpp:30:52: error: invalid types ‘int[int]’ for array subscript  
  12. result[size]=subtract(num1[size],num2[size]);  
  13. ^  
  14. main.cpp:30:63: error: invalid types ‘int[int]’ for array subscript  
  15. result[size]=subtract(num1[size],num2[size]);  
  16. ^  
  17. main.cpp:30:64: error: ‘subtract’ was not declared in this scope  
  18. result[size]=subtract(num1[size],num2[size]);  
  19. ^  
  20. main.cpp:34:52: error: invalid types ‘int[int]’ for array subscript  
  21. result[size]=multiply(num1[size],num2[size]);  
  22. ^  
  23. main.cpp:34:63: error: invalid types ‘int[int]’ for array subscript  
  24. result[size]=multiply(num1[size],num2[size]);  
  25.    
c++ programme:
 
 
  1. using namespace std;  
  2. #include   
  3.   
  4. int main()  
  5. {   
  6.     int size,num1,num2;  
  7.     char operation[size];  
  8.     int result[size];  
  9.       
  10.     do{  
  11.             cout << "Crud Operation in c++   : \n"  
  12.              << "   +   --- Addition  \n"  
  13.              << "   -   --- Subtraction   \n"  
  14.              << "   *   --- Multiplication   \n"  
  15.              << "   /   --- Division   \n"  
  16.              << "   %   --- Remainder   \n";  
  17.             cout<<"Answer: ";  
  18.             cin>>operation[size];  
  19.               
  20.             cout<
  21.              
  22.             switch(operation[size])  
  23.             {  
  24.                 case '+':  
  25.                     result[size]=add(num1[size],num2[size]);  
  26.                     cout<
  27.                     break;  
  28.                       
  29.                 case '-':  
  30.                     result[size]=subtract(num1[size],num2[size]);  
  31.                     break;  
  32.                       
  33.                 case '*':  
  34.                     result[size]=multiply(num1[size],num2[size]);  
  35.                     break;  
  36.                       
  37.                 case '/':  
  38.                     if(num2[size]==0)  
  39.                     {  
  40.                         system("cls");  
  41.                         cout<<"ANY NUMBER DIVIDED BY ZERO IS: UNDEFINED.\n\n";  
  42.                         continue;  
  43.                     }  
  44.                     result[size]=divide(num1[size],num2[size]);  
  45.                     break;  
  46.                       
  47.                 case '%':  
  48.                     result[size]=remainder(num1[size],num2[size]);  
  49.                     break;  
  50.           
  51.                 default:  
  52.                     operation[size]= 0;   
  53.                     system("cls");  
  54.                     cout<<"PLEASE ENTER A VALID OPERATION.\n\n";  
  55.                     cout<<"First Number: "<
  56.                     cout<<"Second Number: "<
  57.                     cout<
  58.             }  
  59.         }  
  60.     while(!(operation[size]));     
  61. }   
 
 how to solve this error help?
 
why my programme is not run which place I m going wrong? 

Answers (1)