Question: My homework is to convert an integer to words. For example an input of 1234 should give an output of One Two Three Four .

My homework is to convert an integer to words. For example an input of 1234 should give an output of "One Two Three Four ". We are not allowed to use strings. Can you tell me why my code does not even give an output?

#define _CRT_SECURE_NO_WARNINGS #include #include int main() { int num, digit, digits,power; printf("Please enter your phone number (no longer than 10 digits): "); scanf("%d", &num); while (num > 0) { if (num <= 9&&num>0) { digits = 1; } if (num < 100&&num>=10) { digits = 2; } else if (num < 1000&&num>=100) { digits = 3; } else if (num < 10000&&num>=1000) { digits = 4; } else if (num < 100000&&num>=10000) { digits = 5; } else if (num < 1000000&&num>=100000) { digits = 6; } else if (num < 10000000&&num>=1000000) { digits = 7; } else if (num < 100000000&&num>=10000000) { digits = 8; } else if (num < 1000000000&&num>=100000000) { digits = 9; } else { digits = 10; } power = pow(10, digits); digit = num % power; num = num - (digit*power); switch (digit) { case 1: printf("One "); break; case 2: printf("Two "); break; case 3: printf("Three "); break; case 4: printf("Four "); break; case 5: printf("Five "); break; case 6: printf("Six "); break; case 7: printf("Seven "); break; case 8: printf("Eight "); break; case 9: printf("Nine "); break;

} } return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!