Hello all! This is for the C programming language. Objectives: perform calculati
ID: 3605929 • Letter: H
Question
Hello all! This is for the C programming language.
Objectives:
perform calculations based on multiple conditions
use nested if statements
Task:
Write a well-documented program that is for a hypothetical business that boards dogs. It charges clients a daily rate that is based on both the weight of the dog and the number of days per month in a client's contract. The business also offers the option of premium dog food that adds an additional charge per day based on different weight criteria.
Follow these steps for Lab 8:
Declare the variables needed for the input, calculations, and output. Assume that the weight of the dog in pounds and the number of days per month will be entered as whole numbers. As shown in the examples below, you can use an integer variable to determine whether or not the client wishes to include premium food.
Before you start with the code, it would be a great idea to write out your logic as comments.
The three input amounts should be aligned using the tab character.
Please do not try to use logical operators to combine conditional statements for this problem. It will be highly inefficient and might make your head explode trying to keep every scenario straight. Instead, use nested if statements to determine the rate. An excellent goal for any program is to complete it correctly using as few if statements as possible.
The table below shows the daily rates:
If the client chooses the premium food option, add an additional $1 per day to the rate for dogs 20 pounds or under and $2 per day for dogs over 20 pounds.
The output should be dynamic, meaning the weight and days entered by the user should be displayed in the line that describes what values the rate and monthly total are based on. That line should also include the text with premium food if that option was selected (but nothing if it was not selected). In either case, that line should always end with a colon (:) and, to make the code as efficient as possible, there should only be one instance of code that writes the line that begins To board a....
Once the rate is found, the total is calculated by taking the rate times the days per month. The amounts should be shown with 2 decimal places and a $ sign. Do not worry about tax for this assignment.
Be sure to include a blank line between the inputs and the results. Do your best to make it neat.
Example 1:
Example 2:
Example 3:
Example 4:
Weight 1 - 10 days per month 11 or more days per month Under 10 pounds $12 $10 10 pounds - under 35 pounds $16 $13 35 pounds and over $19 $17Explanation / Answer
#include <stdio.h>
int main(void) {
int weight,days,foodtype,charge;
float ratePerDay;
printf("How many pounds does your dog weigh? ");
scanf("%d",&weight);
printf(" How many days per month for boarding? ");
scanf("%d",&days);
printf(" Premium food? (1 = yes or 2 = no) ");
scanf("%d",&foodtype);
//nested if conditions
if(weight < 10)
{
if(days >= 1 && days <= 10)
ratePerDay = 12;
else if(days >=11)
ratePerDay = 10;
}
else if( weight > 10 && weight <35)
{
if(days >= 1 && days <= 10)
ratePerDay = 16;
else if(days >=11)
ratePerDay = 13;
}
else if(weight >=35)
{
if(days >= 1 && days <= 10)
ratePerDay = 19;
else if(days >=11)
ratePerDay = 17;
}
if(foodtype == 1)
{
if(weight <= 20)
{
charge = days;
}
else if(weight > 20)
{
charge = 2*days;
}
}
//additional premium food charge
ratePerDay = ratePerDay + charge/days;
printf(" To board a %d pound dog for %d days:",weight,days);
printf(" Rate per day: $%.2f",ratePerDay);
printf(" Monthly charges: $%.2f",ratePerDay*days);
return 0;
}
Output:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.