mardi 20 septembre 2022

Why does this simple code keep showing this error?

So this is a simple function to calculate the sum of digits of a number. But I keep getting two errors when I try and run it. Here is the code:

#include <iostream>
#include<climits>
int main(){
    int x;
    std::cout<<"Enter a number : ";
    std::cin>>x ;
    int myfunction(x){
        int count;
        while (x<0){
            x%10;
            count+=1;
         }
        return count;
    }
    int z=myfunction(x);
    std::cout<<z;
return 0;  
}

I'm not really worried about whether the function accurately counts the number of digits. I just want to know why it keeps showing these two error messages:

error: 'myfunction' cannot be used as a function

Aucun commentaire:

Enregistrer un commentaire