0

Using only the function pow() of the cmath library, how can I do that?

this is what I've done so far and it is not working with me. What am I doing wrong?

int main()
{
  long long n;
  cin >> n; 
    
   if(n > 1000 || n < -1000){

    for(int i = n, time = 1; i!=0; i/=10, time++){
      
      int first = i;
      
      while(first >= 10){
        first /= 10;
      }
      
      cout << first;
      
      if(time%3 == 0){
        cout <<',';
      }
    }
    
  }
  
  else{
    cout << n;
  }
  
  return 0;
}
  • 2
    Please describe exactly what goes wrong when you run the program. – cigien Feb 11 '21 at 05:37
  • I guess this is homework (weird case...) can you use to_string or std::vector or std::string? – user202729 Feb 11 '21 at 06:05
  • 1
    You simply have a wrong algorithm. Use a debugger or a pen and paper to find out what happens inside (print out the values of `first`). – Daniel Langr Feb 11 '21 at 06:18
  • @cigien Can't say it's a duplicate, because (1) this is C++ and `printf` is not good and (2) OP's homework has specific different requirements. – user202729 Feb 11 '21 at 06:29
  • @user202729 Yes, I agree. I voted to close as No MCVE. It appears that at least one, and possibly two other users voted to close as duplicate, so that's what shows up on the banner. – cigien Feb 11 '21 at 07:01

0 Answers0