in order to purchase an old car, the depreciated value can be calculated as per the
tariff given below:
Rate of depreciation
No. of years used
10%
20%
30%
3
50%
60%
Above 4 years
Write a menu driven program to input showroom price and the number of years the car
is used ('1' for one year old, '2' for two years old and so on). Calculate the depreciated
value. Display the original price of the car, depreciated value and the amount to be
paid.
Answers
Biggest Of Three Numbers Using Conditional operator/Ternary Operator in C
# include <stdio.h>
void main()
{
int a, b, c, big ;
printf("Enter three numbers : ") ;
scanf("%d %d %d", &a, &b, &c) ;
big = a > b ? ( a > c ? a : c) : (b > c ? b : c) ;
printf("\nThe biggest number is : %d", big)
Answer:
import java.util.Scanner;
public class HelloWorld{
public static void main(String []args){
Scanner sc=new Scanner(System.in);
double price,dep;
int year;
System.out.println("Enter showroom price");
price=sc.nextFloat();
System.out.println("Enter numbers of years car is used ");
year=sc.nextInt();
switch(year)
{
case 1:
dep=price*0.1;
break;
case 2:
dep=price*0.2;
break;
case 3:
dep=price*0.3;
break;
case 4:
dep=price*0.5;
break;
default:
dep=price*0.6;
}
System.out.println("Original Price : "+price);
System.out.println("Depriciated Value : "+dep);
System.out.println("Amount to be paid : "+(price-dep));
}
}
Explanation:
Hope it helps :-)