Create the code as directed in the attached file #include using namespace std; i
ID: 3930499 • Letter: C
Question
Create the code as directed in the attached file #include using namespace std; int main() { // define a character variable called answer // prompt the user to enter their favorite flavor of ice cream // output the following menu: // a : vanilla // b : chocolate // c : strawberry // d : coffee // read the user's answer into the answer variable. // create an if statement so that if the user chooses //a - print "goes great with fudge sauce" // b - print "even better with chocolate jimmies" // c OR d - print "my favorites too!" // anything else - print "Thank you for your vote!" // create a switch statement using answer as the condition, // using the same outputs system("pause"); return 0; }Explanation / Answer
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
char answer;
cout<<"enter your favourite flavour if ice cream ";
cout<<" a:vanilla b:chocolate c:strawberry d:coffee";
cin>>answer;
if(answer=='a'||answer=='A')
cout<<" goes great with fudge sauce";
else if(answer=='b'||answer=='B')
cout<<" even better with chocolate jimmies";
else if(answer=='c'||answer=='C'||answer=='d'||answer=='D')
cout<<" my favourite too !";
else cout<<" Thank you for your vote!";
switch(toLower(answer))
{
case 'a':
cout<<" goes great with fudge sauce";
break;
case 'b':
cout<<" even better with chocolate jimmies";
break;
case 'c':
cout<<" my favourite too !";
break;
case 'd':
cout<<" my favourite too!";
break;
default:
cout<<" Thank you for your vote!";
}
system("pause");
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.