0

A programme to compute rental charge of a bike when rent is charged as follows:-

1)no.of days=1 to 5 days then rent = rupees 400 per day (2)no. days=6 to 10 days then rent = rupees 300 per day + rent of 1 to 5 days (3) no.of days = 11 to 15 then rent = rupees 200 per day + rent of 1 to 5 days + 6 to 10 days (4) no.of days = above 15 days then rent = rupees 100 per day + rent of 1 to 5 + 6 to 10 + 11 to 15 days. Calculate the rent amount and print.!!!!! When the no.of days = 16

7th Jan 2017, 2:37 PM
Amish Arya
Amish Arya - avatar
1 Resposta
0
you can use for loop for iterating over days... and if else if statements for changing rates.. following is the code ********* int rentTotal =0; //we will add our total rent here int daysTotal =16; //we will use for loop to cycle for whole 16 daye for(int day=1;day<=daysTotal;day ++){ int rent = 100; //switching rent rates according to number of day if(day<=5){rent=400;} else if((day>5)&&(day<=10)){rent=300;} else if((day>10)&&(day<=15)){rent=200;} //now add rent in rentTotal rentTotal += rent; } //finally print rentTotal System.out.print(rentTotal); ****** note: rentTotal += rent; //this is same as rentTotal=rentTotal+rent;
7th Jan 2017, 9:39 PM
Pankaj Vaghela
Pankaj Vaghela - avatar