Write a function whose prototype is

string NumberToName(int x);

that returns the string of english name of each digit of number x.
Using this function, write a main program that reads a positive integer number and prints the
english name of each digit of that number in a single line as demonstrated in the following examples.

Example 1:

Enter a positive integer: 16903
16903 ==> ONE SIX NINE ZERO THREE


Example 2:

Enter a positive integer: 407
407 ==> FOUR ZERO SEVEN

how writting this program in c++??????

Recommended Answers

All 3 Replies

Write a function whose prototype is

string NumberToName(int x);

that returns the string of english name of each digit of number x.
Using this function, write a main program that reads a positive integer number and prints the
english name of each digit of that number in a single line as demonstrated in the following examples.

Example 1:

Enter a positive integer: 16903
16903 ==> ONE SIX NINE ZERO THREE


Example 2:

Enter a positive integer: 407
407 ==> FOUR ZERO SEVEN

how writting this program in c++??????

There are several parts to this assignment. You need to pick a strategy and show an attempt at at least one part of the program in order to get help. Some of the aspects are:

  1. Writing the function itself.
  2. Writing the main function.

In the main function, you need to:

  1. Ask for input.
  2. Call the function.
  3. Harness the return value of the function.
  4. Output that value.

In the function, you need to:

  1. Isolate digits.
  2. Convert digits to strings.
  3. Concatenate the string digits.
  4. Return the result.

A good start would be to write a function that returns "ONE SIX NINE ZERO THREE". Write the main function that asks for input, calls the function, and displays the output. Then tackle the function itself and some of the parts that I listed.

If you want more help, you are going to have to post an attempt and a much more specific question.

Well , you can either copy it or learn it , because i did this for you.
What does this do?
I am going to vector all the answers possible , after that will read a number as a char . Why ? Because i will use the char elements that have an ascii code , that i diminish with 48 to get the number , if you don't get it check out an Ascii Table
After that I'll simply successively show the numbers . Hope this helped

#include <iostream>

using namespace std;

char *number[10],nr[100];
int i;

int main(){
    //Assign the text for the numbers
    number[0]="Zero";
    number[1]="One";number[2]="Two";number[3]="Three";
    number[4]="Four";number[5]="Five";number[6]="Six";
    number[7]="Seven";number[8]="Eight";number[9]="Nine";
    //read the nr as a char
    cin>>nr;
    // I'll just cout the Text_Assigned_for_numbers[the_number_I'll_show[i]-48]
    for(i=0;i<=100;i++){cout<<number[nr[i]-48]<<" ";}

}
{cout<<number[nr[i]-48]<<" ";}

why you put this number[nr-48]<<"
. there is other way ..
we can search about the value and print it as char

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.