here is the assignment .

To make telephone numbers easier to remember, some companies use letters to show their telephone number. For example, using letters, the telephone number 438-5626 can be shown as GET LOAN. In some cases, to make a telephone number more meaningful, companies might use more than seven letters. For example, 225-5466 can be displayed as CALL HOME, which uses eight letters. Write a program that prompts the user to enter a telephone number expressed in letters and outputs the corresponding telephone number in digits. If the user enters more than 7 letters, then process only the first seven letters. Also output the - (hyphen) after the third digit. Allow the user to use both uppercase and lowercase letters as well as spaces between words. Moreover, your program should process as many telephone numbers as the user wants.

so here is where my problem is .. my thinking tell me that i will need the user to input a phrase for the telephone number and i would ask the user to enter a special character at the end of the phrase . eg. CALL HOME$.
than i would use two loops one that reads each letter and than prints the corresponding number and will stop doing so till it gets to the point reading the dollar sign .. that is what i thought. Here is the problem i don't know what command reads a single character out of the phrase !. than i would use the break statement after printing each number and the loop would start again . i can print the hyphen by using the count command .. but the problem is at how do i read single character from a phrase . and of course i will face many other after that but for now i need to know how to do that . and if someone can explain in detail how that command works i would highly appreciate it .. plzzz its due on next Tuesday but i want to finish it till Sunday.

If you're taking the input phrase into a string (char array based or string type) simply access the individual characters as array elements.

string s;
cin >> s;
for( int i = 0; i < whatever; i++)
    cout << s[i];

If you're taking the input phrase into a string (char array based or string type) simply access the individual characters as array elements.

string s;
cin >> s;
for( int i = 0; i < whatever; i++)
    cout << s[i];

i am sorry i havent got to arrays yet in my course all i have learnt is . control statements, loops and arithmetic so i can not use it

There is no way to do that without the use of arrays, or some array based library algorithm. What form of string are you using? Because I think in the string.h library there is some commands for doing this kind of thing - although I'm sure you haven't learned about them if you haven't yet learned about arrays. Perhaps you can impress your teacher using the above method.

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.