Asked by Sarim Javaid

Write a program to give discount of 20% if age is less than 15 or greater than 60 to customer otherwise gives only 5% discount.

Answers

Answered by Anonymous
double discount = 0.05;
if (age < 15 || age > 60) discount = 0.20;

price *= (1 - discount);

This isn't a complete program of course, as the question doesn't specify where the age comes from (entered by the user, or stored in an existing data structure?). It just includes how the discount is calculated, as well as how the discount affects the price. Basically, what I've written here can be plugged into an existing program that already defines the variables "age" and "price".

There are no AI answers yet. The ability to request AI answers is coming soon!

Related Questions