Answer:
int main() {
string pet; //stores the pet string which is cat or dog
char spayed; // stores the choice from y or n
cout << "Enter the pet type (cat or dog): "; //prompts user to enter pet type
cin >> pet; //reads the input from user
if(pet=="cat"|| pet=="dog") { // if user enters cat or dog
cout << "Has the pet been spayed or neutered (y/n)? ";
//asks user about pet been spayed of neutered
cin >> spayed;} //reads y or n input by the user
else // else part will execute if user enters anything other than cat or dog
cout<<"only cats and dogs need pet tags";
// displays this message if input value of pet is other than cat or dog
Step-by-step explanation:
The answer to the complete question is provided below:
#include <string>
using namespace std;
int main() {
string pet; // "cat" or "dog"
char spayed; // 'y' or 'n'
// Get pet type and spaying information
cout << "Enter the pet type (cat or dog): ";
cin >> pet;
if(pet=="cat"|| pet=="dog") {
cout << "Has the pet been spayed or neutered (y/n)? ";
cin >> spayed;}
else
cout<<"only cats and dogs need pet tags";
// Determine the pet tag fee
if (pet == "cat")
if (spayed == 'y'
else if (pet == "dog")
spayed=='Y')
cout << "Fee is $6.00 \\";
else
cout << "Fee is $12.00 \\";
return 0; }
According to part a) of this question the OR operator is used in this statement if (spayed == 'y' || spayed=='Y') so that if the user enters capital Y or small y letter both are acceptable.
According to the part b) if(pet=="cat"|| pet=="dog") statement is used to make program only execute spay/neuter prompt and input when the pet type is cat or dog otherwise the program displays the message: only cats and dogs need pet tags.