+ 1

How to solve I didn't understand question❓

Title: Fare Problem: John is travelling by train, The fare of the train depends on the kilometer he traveled. For the first A kilometer, the fare is M and for the subsequent distance, it is N per kilometer. You are given total distance covered by train. Find out the total fare. Input: Each input contains four space separated Integer A,M,N,D(total distance). Output: Print the value of total fare. Constraints: 1<=A,M,N,D<=1000 Sample Input: 1 2 3 5 Sample Output: 14

21st Oct 2019, 8:13 AM
aejaz ahmed
aejaz ahmed - avatar
7 Answers
+ 4
A=1 <- first km M=2 <- fare for the first km N=3 <- fare per km after the first km D=5 <- total distance so for the first km the fare is 2. since the total distance is 5km minus the first kilometer 1km, the distance left is 4km, for this 4km price is 3 (because its no longer the first km) so 3 x 4km is 12 12 plus first km fare (2) 12+2 total fare is 14
21st Oct 2019, 8:38 AM
Taste
Taste - avatar
+ 5
aejaz ahmed another thing, If you want to mention someone, type @ before their name, not # Like Taste you tried to mention :)
23rd Oct 2019, 8:13 AM
HumayrađŸ‡§đŸ‡©
HumayrađŸ‡§đŸ‡© - avatar
+ 4
a*m + (d - a) * n for first a km its m = a*m remaining dist = (d-a) remaining fare = (d-a)*n
21st Oct 2019, 8:34 AM
xyz$
23rd Oct 2019, 2:57 PM
aejaz ahmed
aejaz ahmed - avatar
0
Fare value = fare + (distance travelled * price per km) D = M + (A*N) That's the answer if I correctly understood your question.
21st Oct 2019, 8:45 AM
Fernando Pozzetti
Fernando Pozzetti - avatar
0
Thanks guys đŸ‘«đŸ‘ŹđŸ‘­ I understood the questions and special thanks #taste
21st Oct 2019, 10:30 AM
aejaz ahmed
aejaz ahmed - avatar
0
Taste great explanation! I got the excercise wrong.
21st Oct 2019, 8:38 PM
Fernando Pozzetti
Fernando Pozzetti - avatar