Given an order amount, write an R script that applies a 10% discount if the order amount is more than $20. Print the final amount after discount, or the original amount if no discount is applied.
Question
Given an order amount, write an R script that applies a 10% discount if the order amount is more than $20. Print the final amount after discount, or the original amount if no discount is applied.
Solution
Sure, here is a simple R script that applies a 10% discount if the order amount is more than $20.
# Define the order amount
order_amount <- 25
# Check if the order amount is more than $20
if (order_amount > 20) {
# Apply a 10% discount
final_amount <- order_amount * 0.9
} else {
# No discount is applied
final_amount <- order_amount
}
# Print the final amount
print(final_amount)
In this script, we first define the order amount. Then we check if the order amount is more than $20. If it is, we apply a 10% discount by multiplying the order amount by 0.9. If it's not, the final amount is the same as the order amount. Finally, we print the final amount.
Similar Questions
Discount Calculator:Build a program that calculates the discounted price of an item based on the original price and a discount percentage. If the original price is greater than 1000, apply a 10% discount; otherwise, apply a 5% discount.
Single File Programming QuestionProblem StatementMeet Alex, a budget-savvy shopper who wants to give discounts to customers in the following ways:If the amount is greater than 5000 (not inclusive), the discount is 20%.If it is greater than 2000 (not inclusive), the discount is 15%.10% discount for a purchase amount greater than 1000 (not inclusive). Write a program that takes the amount as input and calculates the discounts using a function named applyDiscount. The discount rates are set as 10%, 15%, and 20% as global double datatype variables.Input format :The input consists of a double value representing the amount.Output format :The output displays "Discounted amount: " followed by a double value representing the discounted amount, rounded to two decimal places.Refer to the sample output for the formatting specifications.Code constraints :In this scenario, the test cases fall under the following constraints:1000.0 ≤ Amount ≤ 10000.0Sample test cases :Input 1 :2000.0Output 1 :Discounted amount: 1800.00Input 2 :1100.50Output 2 :Discounted amount: 990.45Input 3 :10000.0Output 3 :Discounted amount: 8000.00Input 4 :1000.0Output 4 :Discounted amount: 1000.00
You want to offer a new customer a 5 percent discount on the customer's first order. If there are three items on the invoice, how will you apply the discount?Select an answer:Total the invoice items, and then enter Discount 5% below the total.Subtotal the invoice items, and then enter Discount 5% below the subtotal.Enter Discount 5 below the last item on the invoice.Enter Discount 5% below the last item on the invoice.
A single discount equivalent to the discount series of 20%, 10% and 5% is?
A trader gives successive discounts of 10%, 20% and 10% respectively. The percentage of the original cost price he will recover is:
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.