Problem with my looping. Please help.

closed account (Sh59216C)
I am new to C++. For my HW, I need to setup a program that can convert 7 letters into 7 digits phone number. I did that. But I am trying to make the program not returning to window, after converting first set of numbers. Instead, I want to allow user to choose whether to convert more numbers w/o exiting the program. Please look at my codes and tell me what I have done wrong. Thank you in advance.

#include <iostream>
#include <cctype>

using namespace std;

int main()
{
char letter, activation;
int i;
i =0;

cout << "This is a program to convert letters to corresponding telephone numbers." << endl;
cout << "\nEnter '!' to start the program now or enter any letter to start." << endl;

cin >> activation;
while (activation == '!')
{
cout << "Program started." << endl;
cout << "Please enter 7 letters for the program to convert them into 7-digit telephone number." << endl;

for (i = 0; i < 7; i++) // so that any letters after 7th will be deregarded
{

if (i == 0)
cout << "The letters you wish to convert: " ;

if (i == 3)
cout << "-"; // to make a hyphen when after the third digit

cin >> letter;
letter = toupper(letter);

if (i == 0)
cout << "The corresponding number is: " ;

if (letter >= 'A' && letter <= 'Z')
switch (letter)
{
case 'A':
case 'B':
case 'C':
cout << "2" ;
break;
case 'D':
case 'E':
case 'F':
cout << "3" ;
break;
case 'G':
case 'H':
case 'I':
cout << "4" ;
break;
case 'J':
case 'K':
case 'L':
cout << "5" ;
break;
case 'M':
case 'N':
case 'O':
cout << "6" ;
break;
case 'P':
case 'Q':
case 'R':
case 'S':
cout << "7" ;
break;
case 'T':
case 'U':
case 'V':
cout << "8" ;
break;
case 'W':
case 'X':
case 'Y':
case 'Z':
cout << "9" ;
break;
default:
cout << "Invalid data." ;

} // end of if
else
cout << "Invalid input. \n Please enter a letter again." << endl;

} // end of for

cout << "Enter '!' again if you wish to continue entering new numbers.";
cin >> activation;
i = 0 ;

} // end of while

cout << "\nBye!" << endl;
system("pause");
return 0;

} // end of program
Please use [ code ] [ /code ] tags (with no spaces), like this:

std::cout << "So easy to read...\n";

std::cout << "Not so much...\n";
Topic archived. No new replies allowed.