Do I have to use a switch statement for this PLEASE HELP


Anyone know how to code this without the switch statement?





switch(count)
{
case 0:teens = (numberArray[count]);
teensToWords(teens, count);
printf("hundred ");
break;
//since numbers in this place can be represented as a "teen"
//the program needs to combine two numbers to send to the function.
case 1:teens = ((numberArray[count] * 10) + numberArray[count + 1]);
teensToWords(teens, count);
break;
case 2:teens = numberArray[count];
teensToWords(teens, count);
printf("thousand ");
break;
case 3:teens = (numberArray[count]);
teensToWords(teens, count);
//allows the program to ignore a 0 in the hundreds place.
//prevents 12000 from being displayed as "two thousand hundred one."
if (numberArray[count - 1] > 0)
printf("hundred ");
break;
case 4:teens = ((numberArray[count] * 10) + numberArray[count + 1]);
teensToWords(teens, count);
break;
case 5:teens = numberArray[count];
//prints a '-' character to numbers like "forty-five"
if (numberArray[count - 1] != 0)
printf("\b-");
teensToWords(teens, count);
break;

}

}
Your code posting is incomplete to give any real thorough advice in my opinion. You could swap the switch statement for if's..but I don't think that'll really help.

Please repost your code with the code format tags and more code so that we can read your code better and give you better feedback. You could also use [ code][ /code] (without the space between [ and c and [ and /) with your tags if you don't know where the format tag button is.
closed account (D4S8vCM9)
Switch statements can almost always be replaced by the use of polymorphism.
Otherwise I agree to @Elidor. Post it more readable and I can give better hints.
Didn't think about that Velnais but yea your right although it might be more overexerting than the original intention if the classes can't be put to better use later on.
Topic archived. No new replies allowed.