In: Computer Science
Use c++language Use the pseudocode description below to write a program that uses an if, else if, else decision structure for a program that will determine if someone lives in Boston. 1. display message that describes what the program will do. 2. ask the user to input an answer to the question: Do you live in Boston?. 3. if they entered 'y', display a message confirming that they live in Boston. 4. if they entered 'n' , display a message confirming that they don't live in Boston. 5. if they entered an invalid entry, display a message telling them.
I have uploaded the Images of the code, Typed code and Output of the Code. I have provided explanation using comments (read them for better understanding).
Images of the Code:
Note: If the below code is missing indentation please refer
code Images
Typed Code:
// including required Headers
#include <iostream>
using namespace std;
int main()
{
// 1) Displaying message what the Program do
cout << "This Program determines whether someone lives in
Boston or Not\n";
// A character variable to store user input
char input;
//2) asking your for input to the Question
// printing in the Question
cout << "Do you live in Boston? [y/n]: ";
// reading input from using
cin >> input ;
// Constructing a if else if else decision structure
// 3) if user input is 'y'
if(input == 'y')
{
// Displaying confirmation message
cout << "You Live in Boston\n";
// Note: You can modify the confirmation message based on your
requirement
}
// 4) if user input is 'n'
else if(input == 'n')
{
// Displaying confirmation message
cout << "You don't live in Boston\n";
// Note: You can modify the confirmation message based on your
requirement
}
// 5) if user entered an Invalid input
else
{
// printing the Invalid Entry message
cout << "Oops..! Invalid Entry\n";
// Note: You can modify the error message based on your
requirement
}
// returning 0
return 0;
}
//code ended here
Output:
If
You Have Any Doubts. Please Ask Using Comments.
Have A Great Day!