Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions