Hello,
This program uses the telephone key alphabet, the user enters 7 or more chars and the program is suppose to take the first 7 char and turn them into the corresponding 7 digit telephone number, I keep getting 222-2222, the first "if "statement in my for loop. Can anybody help?
[code=cpp]
#include <iostream>
using namespace std;
int main()
{
char ch[7];
int n[7];
int i;
cout << "Enter the letters your wish to convert to a 7 digit phone number" << endl;
cin >> ch[0] >> ch[1] >> ch[2] >> ch[3] >> ch[4] >> ch[5] >> ch[6];
for (i=0;i<7;i++)
{
if (ch[i] == 'a'||'A'||'b'|| 'B'||'c'||'C'){
n[i]=2;}
else if (ch[i] == 'd'||'D'||'e'|| 'E'||'f'||'F'){
n[i]=3;}
else if (ch[i] == 'g'||'G'||'h'|| 'H'||'i'||'I'){
n[i]=4;}
else if (ch[i] == 'j'||'J'||'k'|| 'K'||'l'||'L'){
n[i]=5;}
else if (ch[i] == 'm'||'M'||'n'|| 'N'||'o'||'O'){
n[i]=6;}
else if (ch[i] == 'p'||'P'||'q'|| 'Q'||'r'||'R'|| 's'||'S'){
n[i]=7;}
else if (ch[i] == 't'||'T'||'u'|| 'U'||'v'||'V'){
n[i]=8;}
else if (ch[i] == 'w'||'W'||'x'|| 'X'||'y'||'Y'|| 'z'||'Z'){
n[i]=9;}
else
{cout << "error" << endl;}
}
cout << n[0] << n[1] << n[2] << "-" << n[3] << n[4] << n[5] << n[6] << endl;
system ("pause");
return 0;
}
[/code]
This program uses the telephone key alphabet, the user enters 7 or more chars and the program is suppose to take the first 7 char and turn them into the corresponding 7 digit telephone number, I keep getting 222-2222, the first "if "statement in my for loop. Can anybody help?
[code=cpp]
#include <iostream>
using namespace std;
int main()
{
char ch[7];
int n[7];
int i;
cout << "Enter the letters your wish to convert to a 7 digit phone number" << endl;
cin >> ch[0] >> ch[1] >> ch[2] >> ch[3] >> ch[4] >> ch[5] >> ch[6];
for (i=0;i<7;i++)
{
if (ch[i] == 'a'||'A'||'b'|| 'B'||'c'||'C'){
n[i]=2;}
else if (ch[i] == 'd'||'D'||'e'|| 'E'||'f'||'F'){
n[i]=3;}
else if (ch[i] == 'g'||'G'||'h'|| 'H'||'i'||'I'){
n[i]=4;}
else if (ch[i] == 'j'||'J'||'k'|| 'K'||'l'||'L'){
n[i]=5;}
else if (ch[i] == 'm'||'M'||'n'|| 'N'||'o'||'O'){
n[i]=6;}
else if (ch[i] == 'p'||'P'||'q'|| 'Q'||'r'||'R'|| 's'||'S'){
n[i]=7;}
else if (ch[i] == 't'||'T'||'u'|| 'U'||'v'||'V'){
n[i]=8;}
else if (ch[i] == 'w'||'W'||'x'|| 'X'||'y'||'Y'|| 'z'||'Z'){
n[i]=9;}
else
{cout << "error" << endl;}
}
cout << n[0] << n[1] << n[2] << "-" << n[3] << n[4] << n[5] << n[6] << endl;
system ("pause");
return 0;
}
[/code]
Comment