help

Hello, can anyone help with this program?

[The cost of shipping is 3 KD (currency) for the 1st kilo and 1 KD for each additional kilo for the first 49 kilos; 1/2 KD for the rest. Write a program that reads the weight of the shipment (in kilos) and prints the cost of shipping in KD]

I just wanna know how to solve it like should I use the if statement or loop or what?
int kg = xx;

double cost =0;

if(kg>0) kg--; cost +=3;

if(kg>0) for(max 49 time, untill kg>0) kg--; cost+= 1

if(kg>0) for( untill kg>0) kg--; cost+= 0.5
like this?

1
2
3
4
5
6
7
8
9
int kg, max;
    double cost =0;
    	cout<< "The cost of shipping in KD is:"<<endl;
        if (kg>0)
        kg--;
        cost+=3;
        for (max = 49; kg>0; cost+=1;)
        for (kg--; kg>0; cost+=0.5;)
        return 0;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
	int kg;
	double cost =0;
	kg = 2; /// input from user ///	

	if (kg>0)
	{
		kg--;
		cost+=3;	
	}
        
	for(int i=0; i<49 ; i++)
	{
		if (kg>0)
		{
			kg--;
			cost+=1;	
		}
			
	}
        
	while(kg>0)
	{
		kg--;
		cost+=0.5;	
	}
	cout << "cost = " << cost;
thank you so much
Topic archived. No new replies allowed.