I keep getting the error , "control may reach end of non-void function" What am I doing wrong here? I just dont get it right now! I know its something simple and small but I have been here back and forth for about 2 hours wondering what the hell is going on. Sorry I am just venting... Any help would be greatly appreciated!

int main()
{
    int number ;
    int number_rev = 0;

    printf("Enter a number to reverse: ");
    scanf("%d",&number);



    printf("\nReverse of entered number is = %d\n", result (number, number_rev));


}

int result (int number, int number_rev)
{

    while (number != 0)
{
    number_rev = number_rev * 10;
    number_rev = number_rev + number % 10;
    number = number/10;
    return number_rev;
}
}

Update: I removed the return value outside of the while loop but I am still not getting a value. I input a number and nothing happens. No errors at all.

#include <stdio.h>

int result (int number, int number_rev);

int main()
{
    int number ;
    int number_rev = 0;

    printf("Enter a number to reverse: ");
    scanf("%d",&number);



    printf("\nReverse of entered number is = %d\n", result (number, number_rev));


}

int result (int number, int number_rev)
{

    while (number != 0)
{
    number_rev = number_rev * 10;
    number_rev = number_rev + number % 10;
    number = number/10;

}
    return number_rev ;
}

Why does result() have two parameters when only the first parameter is needed?

int result (int number)
{
    int number_rev = 0;
    while (number != 0)
    {
        number_rev = (number_rev * 10) + (number % 10); 
        number = number/10;
    }

    return number_rev;
}
commented: Thank you so much for the help, I don't know what I was thinking when I did the code initially +0

Thank you for the reply. I have corrected my code like you have guided me to do, but, I am still getting nothing printed out. Not sure why this is the case. I will attach my updated code below...

#include <stdio.h>

int result (int number);

int main()
{
    int number ;


    printf("Enter a number to reverse: ");
    scanf("%d",&number);
    printf("\nReverse of entered number is = %d\n", result (number));


}



int result (int number)
{
    int number_rev = 0;
    while (number != 0)
    {
        number_rev = (number_rev * 10) + (number % 10);
        number = number/10;
    }
    return number_rev;
}

there is no error and its working well.

when you run the program and it takes input and gives result and if console window close immediately , you can see console window (ways may be different from compiler to compiler).

or
in main()
you can add some function which are useful for getting input.
normally getch(); is placed at the last.

so use this

int main()
{
    int number ;
    printf("Enter a number to reverse: ");
    scanf("%d",&number);
    printf("\nReverse of entered number is = %d\n", result (number));
    getch();
}

Thank you so much for the help. When I copied + paste the code from what I just uploaded it worked. That is probably the oddest thing ever. I don't know what was going on but Thank you very much!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.