### can anyone help me please ..

2.Write a program that calculates and prints the Total cost of a pet depending on the cost without insurance read from the user and the insurance fee for each pet according to the following rules:
- A dog that is male costs \$50.
- A dog that is female costs \$80.
- A cat that is male costs \$40.
- A cat that is female costs \$60.
- A bird or reptile costs nothing.
- Any other animal generates an error message.
"Sorry!!.. You have typed a wrong animal!!"

The program should prompt the user for the appropriate information, using a code 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).

NOTE: Remember to write the program in a clear style with indentation.

*A Pet Store*

Enter the cost without insurance of your animal (in dollars): 100

Enter the kind of your animal: D

Is your dog has been neutered (Y or N): Y

The Total cost of your dog = 100 + 50 = \$150
at least give me the idea of it please..
you don't know how much I'm confused right now because of it..
C or C++?
C++
Hmm, first I'm not sure why they would ask you if the animal is neutered or not since it has no impact on the cost according to the problem. A more valid question for that line would be is the animal male or female since that DOES affect the cost. Anyway, have you written any code yet or are you still trying to conceptualize how you want to do this? If the latter it seems like you are over-thinking this. Use your example as a template. First you have to output the *A Pet Store* string. Then output the question of the cost, then get the users input for cost which you can store in a variable. Same for the animal type. And lastly for the animals gender (I'm going to assume that they meant gender instead of weather it is neutered or not). Now the only tricky part in all that is IF you actually want to ask "Is your dog a male or female" or "Is your animal male or female" since the first checks the user input from the first line. For that I would use an if statement to check what the user input on the first line. Or you could use a switch.

Anyway, once you have all that input you have to calculate the cost based on the input. Here a series of if else if else etc statements can help you compare the user input and output the correct calculation.

Now, if you've already hammered out some code feel free to post it here. That will at least give us an idea of your thought processes so far and we can refine the program from there. I'd say the most important part of writing a working program, aside from actually understanding the language you are writing it in, is correctly interpreting the problem and converting it into an algorithm which is what you are having difficulty with. Once you do it a few times though it does become easier. :)
Personally, when I feel overwhelmed and I need to design something I try to flowchart it or pseudo-code it. Even if its informally written, at least I can organize my thoughts so that I have something to go by.
The entire thought process when programming is to divide and conquer. This is very true for the design process.

here is my pseudo-code for your program:

display pet store welcome;
ask user how much is base cost of animal;
get animal selection;
calculate the cost;
display the cost;

for "calculate the cost" you would break that down into steps;

if this is a dog and male set cost to \$50
else if this is a dog and female set cost to \$80
else if this is a cat and male set cost to \$40
else if this is a cat and female set cost to \$60
....

Last edited on
This is not complete, you have to finish it.

 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283`` ``````#include #include using namespace std; int MDog=50; int FDog=80; int MCat=40; int FCat=60; int TotalCost=0; string UserChoice; string PetSex; void welcome() { cout << "welcome to *A Pet Store*" << endl; } void UserInput() { cout << "Type animal (D/C) : "; cin >> UserChoice; cout << "Enter the sex of animal (M/F) : "; cin >> PetSex; } void CostCal() { if (UserChoice == "D") { if (PetSex == "M") { TotalCost=TotalCost+MDog; } else if (PetSex == "F") { TotalCost=TotalCost+FDog; } else { cout << "Animal sex can not be determiend" << endl; } } else if (UserChoice == "C") { if (PetSex == "M") { TotalCost=TotalCost+MCat; } else if (PetSex == "F") { TotalCost=TotalCost+FCat; } else { cout << "Animal sex can not be determiend" << endl; } } else { cout << "Sorry!!.. You have typed a wrong animal!!" << endl; } } void Receipt() { cout << UserChoice << endl; cout << PetSex << endl; cout << TotalCost << endl; } int main() { welcome (); UserInput(); CostCal(); Receipt(); return 0; } ``````
can you solve that program other way plz
thankes
Topic archived. No new replies allowed.