Water Bottle Buying

Toukir is new in Dhaka and he just arrived today. He got a chance to study at Notre Dame College. After a full day bus journey and arranging his mess room, he now becomes thirsty. You know that, there is a lack of drinking water in Dhaka and his mess water tank is also empty. So he will go to the market to buy N liter bottled water. Before going to the market, he wants to calculate how much money he needs. Because if all the money is spent, who will give him money! Note that, there is only 1 liter and 2 liter water bottles are available to buy in the market. He will either buy all 1 liter bottles or buy all 2 liter bottles. But if the number of bottles purchased is more than 5, then he will need a rickshaw to bring them. Now if the price of 1 liter water bottles is A Taka, the price of 2 liters water bottles is B Taka and the rickshaw fare from Toukir’s mess to the market is P Taka, can you tell the minimum amount of money Toukir needs to go with to the market?

This is a companion discussion topic for the original entry at https://toph.co/p/water-bottle-buying


using namespace std;

int main() {
int n , a , b , c , d ;
cin >> n ;
cin >> a >> b >> c;

if(n%2==0 && d<=5)
cout << d*b;
else if(n%2==0 && d > 5)
cout << (d*b)+c;
else if(n%2!=0 && n > 5)
cout << (n*a)+c;
else if(n%2!=0 && n <= 5)
cout << n*a;

every time my answer is being accepted in the first 6 test cases … But on the 7 test case , it is showing wrong answer
i need help about the above description.

How could you say, if n is even and d ≤ 5 then d * b is the minimum price?

Print the minimum among (d * b, d * b + c, n * a + c, n * a)

I understand. Thank you for your feedback