program in c++ to input digits and print in words
Answer / a_l_soni
#include "stdafx.h"
void PrintDigit (int a);
void PrintTens (int a);
int g_set = 0;
int _tmain(int argc, _TCHAR* argv[])
{
int a = 1216;
int b = a;
int iValue = 1000;
for (int x = iValue; x >= 1 ; x=x/10)
{
int t = b/x;
switch (x)
{
case 1000:
PrintDigit (t);
printf (" Thousand ");
break;
case 100:
PrintDigit (t);
printf (" Hundred ");
break;
case 10:
PrintTens (b);
break;
case 1:
if (g_set == 0)
{
PrintDigit (t);
}
}
b = b%x;
}
getchar ();
return 0;
}
void PrintDigit (int a)
{
switch (a)
{
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");
}
}
void PrintTens (int a)
{
int x = a / 10;
if (x > 1)
{
int b = a % 10;
switch(x)
{
case 2:
printf ("Twenty ");
break;
case 3:
printf ("Thirty ");
break;
case 4:
printf ("Fourty ");
break;
case 5:
printf ("Fifty ");
break;
case 8:
printf ("Eighty ");
break;
case 6:
case 7:
case 9:
PrintDigit (x);
printf ("ty ");
break;
}
}
else
{
printf ("and ");
g_set = 1;
int b = a % 10;
switch(b)
{
case 1:
printf ("Eleven");
break;
case 2:
printf ("Twelve");
break;
case 3:
printf ("Thirteen");
break;
case 4:
printf ("Fourteen");
break;
case 5:
printf ("Fifteen");
break;
case 8:
printf ("Eighteen");
break;
case 6:
case 7:
case 9:
PrintDigit (b);
printf ("teen ");
break;
}
}
}
To increase the number of digits, application can handle, increase the value of 'iValue' in main () and add an additional case for the value in the main, above 'case 1000:'.
Please vote and let me know....
Is This Answer Correct ? | 14 Yes | 11 No |
What do you mean by static variables?
What is c++ and its features?
Describe public access specifiers?
Define pre-condition and post-condition to a member function in c++?
What kind of problems can be solved by a namespace?
What is function overriding?
what is the difference between linear list linked representaion and linked representation? what is the purpose of representing the linear list in linked represention ? is it not avoiding rules of linear represention?
Write a C++ Program to check whether a number is prime number or not?
Is c++ the best programming language?
Write a program which is required to process the time of a clock in hours and minutes, entered from the keyboard. With this program, there are two requirements for any data entered by a user: 1. The data must be of the correct type (in this case, two ints). 2. The data must be in the correct range: this means that, for the minutes, negative numbers and any number above 59 must be rejected; for the hours, negative numbers and any number above 23 must be rejected. Output error message for invalid data input. Output the time one and a half hour after the time input. i.e. Hour: 22 Min: 32 One and a half hour after 22:32 is 00:02
write a program that reads in a file and counts the number of lines, words, and characters. Your program should ask the user to input a filename. Open the file and report an error if the file does not exist or cannot be opened for some other reason. Then read in the contents of the file and count the number of lines, words, and characters in the file. Also print additional information about the file, such as the longest and shortest words, and longest and shortest lines. For simplicity, we define a word to be one or more characters ending with white space (a space, tab, carriage return, etc.). Functions for checking the types of characters can be found in the ctype.h header file, so you want to include this header file in your program. For example, the sentence below could be all that is in a file. This sentence IT 104 is taught in C++. has 32 characters, one line, and six words. The shortest line is 32 characters. The longest line is 32 characters. The shortest word is 2 characters. The longest word is 6 characters
What do you mean by delegate? Can a user retain delegates?