#include<iostream> using namespace std; int funcIf(char); int funcSwitch(char);
ID: 3652598 • Letter: #
Question
#include<iostream>using namespace std;
int funcIf(char);
int funcSwitch(char);
int main()
{
char a;
cout<<"Enter the letter: ";
cin>>a;
int a1=funcIf(a);
int a2=funcSwitch(a);
cout<<" Using if statement, value is: "<<a1;
cout<<" Using Switch statement, value is: "<<a2;
}
int funcIf(char a)
{
if(a>='a' && a<='c')return 2;
else if(a>='d' && a<='f')return 3;
else if(a>='g' && a<='i')return 4;
else if(a>='j' && a<='l')return 5;
else if(a>='m' && a<='o')return 6;
else if(a>='p' && a<='s')return 7;
else if(a>='t' && a<='v')return 8;
else if(a>='w' && a<='z')return 9;
else return -1;
}
int funcSwitch(char a)
{
switch(a)
{
case 'a':case 'b':case 'c':return 2;break;
case 'd':case 'e':case 'f':return 3;break;
case 'g':case 'h':case 'i':return 4;break;
case 'j':case 'k':case 'l':return 5;break;
case 'm':case 'n':case 'o':return 6;break;
case 'p':case 'q':case 'r': case 's':return 7;break;
case 't':case 'u':case 'v':return 8;break;
case 'w':case 'x':case 'y': case 'z':return 9;break;
default:return -1;
}
}
why when i put enter enter exit automatically?
someone can fix this !
Explanation / Answer
//I'm not sure what compiler you are using, but i tried in codeBlocks and visual studio // and both works in stalling program with either of the two statements #include using namespace std; int funcIf(char); int funcSwitch(char); int main() { char a; char wait; couta; int a1=funcIf(a); int a2=funcSwitch(a); coutRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.