+ 4
In the code below i have used Switch statement. But i want to use(if else) istead of Switch, What changes should i make?
#include <iostream> using namespace std; int main() { char letter; cin>>letter; switch(letter*(letter>='a' && letter<='z')){ case 'a': case 'e': case 'i': case 'o': case 'u': cout<<"you entered a vowel"<<endl; break; case 0:cout<<"that is not a small letter"<<endl; break; default:cout<<"you entered a constant"<<endl; } return 0; }
5 Answers
+ 5
https://code.sololearn.com/cr6DaoUcB8IC/#cpp
#include <iostream>
using namespace std;
int main()
{
char letter;
cin>>letter;
char ltr = letter*(letter>='a' && letter<='z');
// IF-ELSE STATEMENTS
if( ltr == 'a' || ltr == 'e' || ltr == 'i' || ltr == 'o' || ltr == 'u')
{
cout<<"you entered a vowel"<<endl;
} else if(ltr == 0) {
cout<<"that is not a small letter"<<endl;
} else {
cout<<"you entered a constant"<<endl;
}
return 0;
}
+ 5
https://msdn.microsoft.com/en-us/library/y34a3dk2.aspx
if ( expression )
statement1
[else
statement2]
+ 3
@Netkos Ent THANK YOU SO MUCH!
+ 3
You're more than welcome RiGel. Best of luck with your programming journey.
+ 2
@Netkos Ent thank you i appreciate your encouragement!đ