How do I put in a yes or no input statement? Yes for the program to run and no for the program to stop. I also need a yes or no input at the end of the program as well but I still to be getting errors such as "Expected instalizers before 'swtich' on the switch statement. Basically I am trying to prompt the user two times, first before the program executes the main code and after the first iteration of code asking the user if he would like to run the program again.
#include <iostream>
#include <iomanip>
#include <string>
usingnamespace std;
int LettertoNumber (char);
int main()
{
cout <<"-------------------------------------------------------" <<endl;
cout <<"Ani Biswas CSC133-01 Lab02.cpp 09/27/16" <<endl;
cout <<"-------------------------------------------------------" <<endl;
//Declaration of variables
char PhoneNumber[11];
//Beginning of main program
cout<<"This program converts letters to their corresponding telephone digits" <<endl;
{
string input;
cout<<"Input y to start the program and input n to end the program" <<endl;
cin>> input;
if(input.compare("y"))
{
cout<<"Enter a phone number: " <<endl;
cin.getline( PhoneNumber, 11, '/n' ); //Similar to void. cin.getline or the getline member function. Here I am trying to get the compiler to input integers on the line and then remove the terminating characters
cout<<"Phone Number before conversion: " << endl;
cout << PhoneNumber << endl;
for(int i = 0; i < 11; i++)
{
PhoneNumber[i] = LettertoNumber(PhoneNumber[i]);
}
cout<<"Phone Number after conversion: "<< endl;
cout << PhoneNumber << endl;
cout<<"****************************************" <<endl;
}
elseif(input.compare("n"))
{
cout<<"End of program"<<endl;
return 0;
}
int LettertoNumber(char letter)
switch (letter)
{
case'A':
case'B':
case'C':
case'a':
case'b':
case'c':
return'2';
break;
case'D':
case'E':
case'F':
case'd':
case'e':
case'f':
return'3';
break;
case'G':
case'H':
case'I':
case'g':
case'h':
case'i':
return'4';
break;
case'J':
case'K':
case'L':
case'j':
case'k':
case'l':
return'5';
break;
case'M':
case'N':
case'O':
case'm':
case'n':
case'o':
return'6';
break;
case'P':
case'Q':
case'R':
case'S':
case'p':
case'q':
case'r':
case's':
return'7';
break;
case'T':
case'U':
case'V':
case't':
case'u':
case'v':
return'8';
break;
case'W':
case'X':
case'Y':
case'Z':
case'w':
case'x':
case'y':
case'z':
return'9';
break;
default:
return letter; // in case it is not a letter or is already a number
break;
}
}
}