repl.it
@justingraham/

Creating Telephone Number Helper

C++

No description

fork
loading
Files
  • main.cpp
main.cpp
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

char numToLetter(char letter);

int main()
{
	cout << "* - * - * - * Handy Dandy Phone Number Conversion * - * - * - *";
	
	string number;
	cout << "\n\nPlease enter a phone number or '9' to end: ";
	
	cout << "\n\nInput phone number: ";
	cin  >> number;

	while(number != "9")
	{
		for(int pos = 0; pos < number.size(); pos++)
		{
			number[pos] = numToLetter(number[pos]);
		}
	
		cout << "Real phone number: " << number;
		
		cout << "\n\nInput phone number: ";
		cin  >> number;
	}

	cout << "\nThe end\n";
	
	return 0;
}

char numToLetter(char letter)
{
	if(letter == 'A' || letter == 'B' || letter == 'C') 
	return '2';
	
	else if(letter == 'D' || letter == 'E' || letter == 'F') 
	return '3';
	
	else if(letter == 'G' || letter == 'H' || letter == 'I') 
	return '4';
	
	else if(letter == 'J' || letter == 'K' || letter == 'L') 
	return '5';
	
	else if(letter == 'M' || letter == 'N' || letter == 'O') 
	return '6';
	
	else if(letter == 'P' || letter == 'Q' || letter == 'R' || letter == 'S') 
	return '7';
	
	else if(letter == 'T' || letter == 'U' || letter == 'V') 
	return '8';
	
	else if(letter == 'W' || letter == 'X' || letter == 'Y' || letter == 'Z') 
	return '9';
}
Fetching token
?