I haven't programmed in C in a while, and I decided to write a simple program for a friend of mine. It's a numerology program that takes your name, converts each letter into a number in the alphabet (A = 1, B = 2, Z = 26, etc.). I wrote a function that takes a number and splits the digits up, adding them together to form a single digit, and return that digit, only when I run it, it only returns 9, no matter what number I put in (23, 543, 7, etc.) Can you help me? I don't know what I did wrong.
The code below is a program to test the crunch function:
Code:
#include<stdio.h>
int crunch(int num);
int main()
{
int c, d;
printf("Enter a number: ");
scanf("%d", c);
d = crunch(c);
printf("%d", d);
return 0;
}
int crunch(int num)
{
int sum = 0;
int tmp;
while(num != 0)
{
tmp = num % 10;
sum += tmp;
num = num / 10;
}
if(sum >= 10)
return crunch(sum);
return sum;
}