Below is a C++ program to accept any single digit number and print it in words:
C++
#include <iostream>
using namespace std;
int main() {
int n;
cout << "Enter a single digit number: ";
cin >> n;
if (n >= 0 && n <= 9) {
switch (n) {
case
0:
cout << "Zero";
break;
case
1:
cout << "One";
break;
case
2:
cout << "Two";
break;
case
3:
cout << "Three";
break;
case
4:
cout << "Four";
break;
case
5:
cout << "Five";
break;
case
6:
cout << "Six";
break;
case
7:
cout << "Seven";
break;
case
8:
cout << "Eight";
break;
case
9:
cout << "Nine";
break;
}
} else {
cout << "Please enter a single digit number between 0 and 9";
}
return 0;
}
So, the program should work as expected. If the user enters a number between 0 and 9, it will print the corresponding word.
Hence, If the entered number is outside this range, it will display a message asking the user to enter a number between 0 and 9.