0

i'm trying to figure out if there's a way I can extract digits from a number in a left to right direction and display them as individual spaced out digits using mathematical expressions in a loop. Something's wrong with my code, specifically in the last while statement:

numA=numA%pow(10,k);

error: invalid operands of types 'int' and '__gnu_cxx::__promote_2<int, int, double, double>::__type' {aka 'double'} to binary 'operator%'|

This seems to give off an error which I don't quite understand and I've been trying to figure this out for a while, I feel like there's something here I'm so close to getting but i'm not there yet. How can I adjust my code so it can properly extract the digits left to right from a given number?

#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int numA=1546;
int digit,i;
int temp;
int test=0;


temp=numA;

while(temp!=0)
    {
        test=temp%10;
        temp=temp/10;
        cout<<test;
         i++;
    }
    cout<<"\n Our digits are "<<i<<endl;
int j;
j=i+i;

while(j<i)
    {
        int k=j-i;
        digit=numA/pow(10,k);
        numA=numA%pow(10,k);
        cout<<digit<<" ";
         j--;
    }

}

0 Answers0