help!!!

how do i go about getting ride of the "-" in the numbers?

1
2
3
4
5
6
7
8
9
10
11
12
13
1)	Write a program prompts a user for a telephone 
number that requires only one dash in between. The 
program then outputs the telephone number without
 the dash. The fake phone number can be as long as 
the user wants.

Example:
Enter a telephone number: 555-1234
5551234

Enter a telephone number: 99999-245
99999245
Last edited on
There is a function in <cctype> called isdigit(). You can check each digit of the string with isdigit(). If the character is not a digit, just ignore it. Otherwise, copy the digit to your output string.
This is my simple rendition of what you are asking for. Hope this helps :)

This only works for a 7 digit number. Maybe you can modify it yourself.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
using namespace std;

int main()
{
    char num[8];
    
    for (int i = 0; i < 8; i++) {
        cin >> num[i];
        if(num[i] != '-')
        {
            cout << num[i];
        }
    }
    return 0;
}
Last edited on
How did you solve the problem? Did my post help you? Please let me know, thanks.
Topic archived. No new replies allowed.