This program is giving me redefinition of int main() error. But working corrrectly on my system. How to fix it?


  • 0
    S
    #include <iostream>
    

    using namespace std;

    class Solution {

    public:
    int addDigits(int &); //declaration

    int count_a(int);
    

    };

    int Solution::addDigits(int & num){

    int temp=0,sum=0;
    int count=count_a(num);
    
    if(count<1)
    return 0;
    
    if(count==1){
    return num;
    }
    else{
    for(int i=0;i<count;i++){
      temp=num%10;                 //remiander is saved in no
      num=num/10;                
      sum+=temp;
    }
    }
    
    do{
    count=count_a(sum);
    num=sum;
    sum=0;
    temp=0;
    for(int i=0;i<count;i++){
      temp=num%10;                 //remiander is saved in no
      num=num/10;                
      sum+=temp;  
    }
    }while(count>1);
    
    return sum;
    

    }

    int Solution::count_a(int input){

    int c=0;
    do{
        input=input/10;
        c++;
    }while(input!=0);
    
    return c;
    

    }

    int main(){

    Solution ob;             //object of class is declared
    int a,output;
    cout<<"\nEnter the number:";
    cin>>a;
    output=ob.addDigits(a);
    cout<<"\n the final required number is: "<<output;
    return 0;
    

    }


  • 0

    Remove your int main() function. LeetCode OJ does not need you to write manual code to parse input.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.