I am writing this program as homework and I've got it all written. It has no "errors". However it doesn't run correctly. The point of the program is to ask the user what type of animal you are checking into the vet's office. Then ask how much the animal weighs. Then it will give you the cost of the visit based off of what the user inputs. The programs works great until you enter the weight. Then it immediately goes to the default statement, then asks again followed by switching to the completely wrong default statement. I appreciate any help anyone can offer.
Code:
#include <iostream>
using namespace std;
int main ()
{
int weightDog;
int weightCat;
int weightHorse;
char type;
cout << "Welcome to the Vet Office!\n " ;
cout << "Please enter an animal type:\n " ;
cout << "D - Dog\n " ;
cout << "C - Cat\n " ;
cout << "H - Horse\n " ;
cin >> type;
switch(type)
{
{
case 'd':
case 'D': cout << "How much does your dog weigh? ";
cin >> weightDog;
switch(weightDog)
{
if (weightDog >= 1 && weightDog < 25)
{
cout << "Your dog is classified as a small dog.\n";
cout << "Your consultation will cost $70.\n";
break;
}
else if (weightDog >= 25 && weightDog < 70)
{
cout << "Your dog is classified as a medium dog.\n";
cout << "Your consultation will cost $90.\n";
break;
}
else if (weightDog >= 70 && weightDog <= 200)
{
cout << "Your dog is classified as a large dog.\n";
cout << "Your consultation will cost $120.\n";
break;
}
default: cout << "You did not enter a valid weight. Please enter a weight under 70 pounds.\n";
break;
}
}
{
case 'c':
case 'C': cout << "How much does your cat weigh? ";
cin >> weightCat;
switch(weightCat)
{
if (weightCat >= 1 && weightCat < 5)
{
cout << "Your cat is classified as a small cat.\n";
cout << "Your consultation will cost $40.\n";
break;
}
else if (weightCat >= 5 && weightCat < 10)
{
cout << "Your cat is classified as a medium cat.\n";
cout << "Your consultation will cost $50.\n";
break;
}
else if (weightCat >= 10 && weightCat < 30)
{
cout << "Your cat is classified as a large cat.\n";
cout << "Your consultation will cost $60.\n";
break;
}
default: cout << "You did not enter a valid weight. Please enter a weight under 30 pounds.\n";
break;
}
}
{
case 'h':
case 'H': cout << "How much does your horse weigh? ";
cin >> weightHorse;
switch(weightHorse)
{
if (weightHorse >= 1 && weightHorse < 600)
{
cout << "Your horse is classified as a small horse.\n";
cout << "Your consultation will cost $140.\n";
break;
}
else if (weightHorse >= 600 && weightHorse < 1200)
{
cout << "Your horse is classified as a medium horse.\n";
cout << "Your consultation will cost $190.\n";
break;
}
else if (weightHorse >= 1200 && weightHorse < 3500)
{
cout << "Your horse is classified as a large horse.\n";
cout << "Your consultation will cost $220.\n";
break;
}
default: cout << "You did not enter a valid weight. Please enter a weight under 3500 pounds.\n";
break;
}
}
default: cout << "You did not enter a valid option for animal. Please choose D, C, or H.\n ";
}
}