console application

Hi
I am new to programming.I need a solution for the problem.

A user is allowed to enter two digit number(For eg: 26).After the user hits the enter key the program should print the answer as twenty six.If any other two digits is entered such as 48 the program should print it as forty eight. Please provide me the solution. The language maybe C or C++(language doesn't matter). Thanks in advance. Awaiting for the reply. Any reply will be useful.
Hey,

This is easy and hard together. There are many solutions, here is mine:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
#include <cstddef> // size_t is a typedef on an unsigned int

int main ( )
{
     const char* MyStringDigits[] = { "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten" } ;
     std::cout << "Number: " ;
     std::size_t Number ;
     std::cin >> Number ;
     if ( Number > 10 )
          std::cerr << "Hey!! Out of Range!" << std::endl ;
     else
          std::cout << "It's: \"" << MyStringDigits[Number-1] << "\"" << std::endl ;
     return 0 ;
}



bye and have fun (:
Thank you for your time. But your application will print the answer as Two Six(something like that). But what i need is the answer should be printed as Twenty six. Thanking you.
ahhh lol ):

Here is it:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <iostream>
#include <cstddef> // size_t is a typedef on an unsigned int

int main ( )
{
	const char* strDigits_tens[] = { "Ten", "Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety" } ;
	const char* strDigits_ten[] = {  "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen" } ; 
     const char* strDigits_units[] = { "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine" } ;
     
     while(true) // debug
     {
		std::cout << "Number: " ;
		std::size_t Number ;
		std::cin >> Number ;
		
		// Split the Number in two digits:
		std::size_t Digits[2] ;
		Digits[0] = Number/10 ; // example: 98 / 10 = 9
		std::cout << "[DEBUG] " << Digits[0] << std::endl ;
		if ( Digits[0] == 0 ) // if the Number isn't a tens. example: 9/10 = 0
		{
			Digits[1] = Number ;
			std::cout << "It's: " << strDigits_units[Number-1] << std::endl ;
		}
		else
		{
			Digits[1] = Number-Digits[0]*10 ;  // example: 98- (9*10) = 8
			
			if ( Digits[0] == 1 ) // if the first digit is an 1. example: 12
				if ( Digits[1] == 0 )
					std::cout << "It's: " << strDigits_tens[Digits[1]] << std::endl ;
				else
					std::cout << "It's: " << strDigits_ten[Digits[1]-1] << std::endl ;
			else if ( Digits[1] == 0 ) // if the second digit is a 0. example: 30
				std::cout << "It's: " << strDigits_tens[Digits[0]-1] << std::endl ;
			else
				std::cout << "It's: " << strDigits_tens[Digits[0]-1] << "-" << strDigits_units[Digits[1]-1] << std::endl ;
				
		}
	}
	return 0 ;
}


bye and have fun (:
Thank you.i will try it
Topic archived. No new replies allowed.