Hi..Can you please help me to answer my qustion I didn't know how to answer it
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
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;
display menu choices for animal-types;
get animal selection;
ask if animal is spade/neutered;
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