I'm am working on an assignment that involves if and then statements as well as logical operators.
My objective is to write a code for the price of pet tags. They way it works is you must state whether you have a dog or cat. If you have either then you must state whether it has been spayed. Depending on the choice you will get a price. IF you don't have a dog or cat, then it will skip to "Only cats and dogs need pet tags"
My question is that it works seamlessly when I don't use "||" in the "if (spayed == )" argument just as I wrote it when the user writes dog. So if you just type a lower case y, it will work as intended. however one of the objectives of the assignment is to make it work with both lowercase and uppercase Y. I tried to do this with the cat choice, but no matter the input i keep getting the first choice rather than the "else if" statement.
#include <iostream>
#include <string>
usingnamespace 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" || "dog")
{
// Determine the pet tag fee
if (pet == "cat")
{
cout << "Has the pet been spayed or neutered (y/n)? ";
cin >> spayed;
if (spayed == 'y' || 'Y')
cout << "Fee is $4.00 \n";
elseif (spayed == 'n' || 'N')
cout << "Fee is $8.00 \n";
}
elseif (pet == "dog")
{
cout << "Has the pet been spayed or neutered (y/n)? ";
cin >> spayed;
if (spayed == 'y')
cout << "Fee is $6.00 \n";
elseif (spayed == 'n')
cout << "Fee is $12.00 \n";
}
else
cout << "Only cats and dogs need pet tags";
}
return 0;
}