rags_to_riches I saw that. That is what was causing the else error, but I have fixed that part now.
rags_to_riches I saw that. That is what was causing the else error, but I have fixed that part now.
You had two erroneous semicolons. Did you get both of them?
Yea I fixed both of them after the two if statements, but now I cant get output from anything but the onesDig. It outputs stuff like -eight, -two. A couple times it was actually right for the ones digit but now it seems to be random.
I took the code you posted, and made the edits you said you made, and everything looked fine. You know this wont work for single digit numbers, right? Can we get the full code and some sample input to help you debug this?
Yea here's the complete code:
Some sample inputs I tried are 78 45 and it gave me -fourCode:#include <stdio.h> int main(void) { int a, b, num, onesDig, tensDig; printf("Enter two two-digit numbers separated by a space: "); scanf("%d %d", &a, &b); if (a>b){ a=num;} else b=num; onesDig = num%10; tensDig = num/10; if (num) { switch (num){ case 10: printf("ten"); break; case 11: printf("eleven"); break; case 12: printf("twelve"); break; case 13: printf("thirteen"); break; case 14: printf("fourteen"); break; case 15: printf("fifteen"); break; case 16: printf("sixteen"); break; case 17: printf("seventeen"); break; case 18: printf("eighteen"); break; case 19: printf("nineteen"); break; } } else if (tensDig!=1) { switch (tensDig) { case 2: printf("twenty"); break; case 3: printf("thirty"); break; case 4: printf("forty"); break; case 5: printf("fifty"); break; case 6: printf("sixty"); break; case 7: printf("seventy"); break; case 8: printf("eighty"); break; case 9: printf("ninety"); break;} } if (onesDig) { switch (onesDig) { 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; }
89 78= -eight
52 12 = -six
Gah! Why did you change i to num, and change the if to "if (num)"? You were so close. You also still haven't rearranged the order of your assignments! For the THIRD AND FINAL TIME, GET THE BIGGER OF THE TWO NUMBER LIKE THIS:
Assignments in C work like this:Code:if (a > b) { num = a; } else { num = b; }
Also, you haven't put the correct braces around your else block. Look at my example. One outer if-else, to separate "teens" from the rest. Then, two individual if blocks (tens digit and ones digit), both inside the else clause of the if (num >= 10 && num <= 19) statement. Read the dangling else article if you haven't yet, then get in the habit of being explicit with your { } and get an editor that auto-indents code for you to help make this easier.Code:where_you_want_to_put_the_data = where_you_are_getting_the_data_from;
OMG thank you so much. I finally got it working perfectly. I always forget little things that really mess me up. Again thanks for the help I probably wouldn't have gotten it without you.