I'm writing a program in class. You're supposed to write a program that prints out pet insurance fee
Write a program that prints the insurance fee to pay for a pet according to the following rules:
(Note: must use a switch statement to determine pet fee)
A dog that has been neutered costs $50.
A dog that has not been neutered costs $80.
A cat that has been neutered costs $40.
A cat that has not been neutered costs $60.
A bird or reptile costs nothing.
Any other animal generates an error message.
The program should prompt the user for the appropriate information: a character code for the pet type, and a yes/no response for the neutered status. Use a code letter to determine the kind of animal (i.e. D or d represents a dog, C or c represents a cat, B or b represents a bird, R or r represents a reptile, and anything else represents some other kind of animal). Use a code letter to determine the neutered status(i.e. Y or y represents yes, N or n represents no). The user should be allowed to enter the input in either upper or lower case.
It prints out the type of animal (full name of animal) and the insurance fee. Any error in input data should generate an error message “Invalid data – no fee calculated”
NOTE: You must use a switch statement to determine the pet fee.)
I am not sure if I need to use if else statements before using switch statements or if those are completely unnecessary when using a switch.
Also, I don't know how to have it test in the next case for "n" for the char "neutered" because it tells me I have already used "d".
this is what I have so far...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
char animal, neutered;
const int dogcost = 80, catcost = 60, birdOrReptilecost = 0;
//Take inputs
cout << "Pet Insurance Program\n\n";
cout << "Please enter the first letter of the type of animal you would like to insure\n";
cout << fixed << setw(30) << "Dog\n" << setw(30) << "Cat\n" << setw(30) << "Bird\n" << setw(31) << "Reptile\n\n";
cout << "Enter the kind of your animal: ";
cin >> animal;
cout << "Is your pet neutered? ('y' for yes 'n' for no) ";
cin >> neutered;
switch (animal && neutered)
{
case 'd' || 'D' && 'y': cout << "the fee to insure your neutered dog is $" << dogcost - 30 << endl;
break;
}
return 0;
|