#include <iostream>
#define MAX_WEIGHT 3.0
using namespace std;

// function prototypes
float get_price();
float get_weight();
float postage(float, float);

// start main function
int main() {
    float weight = 0; // should not more than 3 kg
    float price = 0;  // should > 0

    weight = get_weight();
    price = get_price();

    cout << "Price not including postage = " << price << "\n\n";

    // The postage function should able calculate and set price
    // which including postage cost
    price=postage(price, weight);

    cout << "Total price including postage = " << price << '\n';

    return 0;
}

// start new user-defined functions
float get_price() {
    float p = 0;

    cout << "\n";
    while (p == 0) {
        cout << "Item price (RM): ";
        cin >> p;
    }

    return p;
}

float get_weight() {
    float w = 0;

    do{
        cout << "Item weight (not more than 3 kg): ";
        cin >> w;
	}while(w>MAX_WEIGHT);

    return w;
}

// weight more than 2 kg postage cost is RM 10
// weight 1 - 2 kg postage cost is RM 7
// weight less than 1 kg postage cost is RM 4
float postage(float p, float w) {
    float post = 0;

    if (w > 2) {
        post = 10;
    } else if (w >= 1) {
        post = 7;
    } else {
        post = 4;
    }

    cout << "Postage cost = " << post << "\n";
    p += post;
    return p;
}
