PART I - Rewrite the following program using the SWITCH( ) statement # include <
ID: 2960436 • Letter: P
Question
PART I - Rewrite the following program using the SWITCH( ) statement# include <iostream>
using namespace std;
int main ( )
{
char letter;
cout <<“ Welcome to _________________ Fruit Stand”;
cout <<“ Please enter in CAPS the First Letter of a fruit: ”;
cin >>letter;
if (letter = = ‘A’)
cout <<“Your fruit is an Apple or an Apricot”;
else if (letter = = ‘O’)
cout <<“Your fruit is an Orange”;
else if (letter = = ‘P’)
cout<< “Your fruit is a Plum or a Pineapple”;
else if (letter = = ‘B’)
cout <<“Your fruit is a Banana”;
else
cout <<“Sorry !! I do not know a Fruit that begins with that letter”;
system (“pause”);
return 0;
}
Explanation / Answer
# include <iostream>
using namespace std;
int main ( )
{
char letter;
cout <<“ Welcome to _________________ Fruit Stand”;
cout <<“ Please enter in CAPS the First Letter of a fruit: ”;
cin >>letter;
switch(letter)
{
case 'A': cout <<“Your fruit is an Apple or an Apricot”; break;
case 'O' : cout <<“Your fruit is an Orange”; break;
case 'P': cout<< “Your fruit is a Plum or a Pineapple”; break;
case 'B': cout <<“Your fruit is a Banana”; break;
default: cout <<“Sorry !! I do not know a Fruit that begins with that letter”; break;
}
system (“pause”);
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.