Изписване на число от 0 до 100 с думи, гърмят ми три теста защо?
#include <iostream>
using namespace std;
#include <string>
int main() {
int num;
int tens= 0;
int units = 0;
string str1;
string str2;
cin >> num;
if (num>=0&&num<=9)
{
switch (num){
case 0: str1 = "zero";
break;
case 1: str1 = "one";
break;
case 2: str1 = "two";
break;
case 3: str1 = "three";
break;
case 4: str1 = "four";
break;
case 5: str1 = "five";
break;
case 6: str1 = "six";
break;
case 7: str1 = "seven";
break;
case 8: str1 = "eight";
break;
case 9: str1 = "nine";
break;
}
}else if(num>=10&&num<=19){
switch (num){
case 10: str1 = "ten";
break;
case 11: str1 = "eleven";
break;
case 12: str1 = "twelve";
break;
case 13: str1 = "thirteen";
break;
case14: str1 = "fourteen";
break;
case 15: str1 = "fifteen";
break;
case 16: str1 = "sixteen";
break;
case 17: str1 = "seventeen";
break;
case 18: str1 = "eighteen";
break;
case 19: str1 = "nineteen";
break;
}
} else if(num>=20&&num<=100) {
tens = num / 10;
units = num % 10;
switch (tens){
case 2: str2 = "twenty";
break;
case 3: str2 = "thirty";
break;
case 4: str2 = "forty";
break;
case 5: str2 = "fifty";
break;
case 6: str2 = "sixty";
break;
case 7: str2 = "seventy";
break;
case 8: str2 = "eighty";
break;
case 9: str2 = "ninety";
break;
case 10: str2 = "one hundred";
break;
}
switch (units){
case 1: str1 = "one";
break;
case 2: str1 = "two";
break;
case 3: str1 = "three";
break;
case 4: str1 = "four";
break;
case 5: str1 = "five";
break;
case 6: str1 = "six";
break;
case 7: str1 = "seven";
break;
case 8: str1 = "eight";
break;
case 9: str1 = "nine";
break;
}
}
if (tens == 0 && units == 0){
cout<<str1<<endl;
}
else if (units == 0){
cout<<str2<<endl;
}
else if (units != 0){
cout<<str2<<" "<<str1<<endl;
}
return 0;
}