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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
#include <iostream>
#include <string>
#include <limits>
//using namespace std; // <--- Best tno to use.
int main()
{
double weight{}, price{};
char i = 'Y';
std::string name, address, phonenumber, postalcode, state, city; // <--- Added City.
while (i != 'N' && i != 'n')
{
std::cout << "\n****************WELCOME TO SUPER POSTAGE SERVICE*******************\n";
std::cout << "\nEnter Customer Name: ";
std::getline(std::cin, name);
std::cout << "\nEnter Customer Address: ";
std::getline(std::cin, address);
std::cout << "Enter City: "; // <--- Added.
std::getline(std::cin, city); // <--- Added.
std::cout << "Enter State: ";
std::getline(std::cin, state);
std::cout << "Postal Code: ";
std::getline(std::cin, postalcode);
std::cout << "Enter Customer Phone Number: ";
std::getline(std::cin, phonenumber);
std::cout << "Enter Items Weight(In Kg) :";
std::cin >> weight;
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); // <--- Requires header file <limits>. // <--- Added.
if (weight < 0.5)
price = 5.9;
else if (weight >= 0.5 && weight < 1.0)
price = 5.9 + 1;
else if (weight >= 1.0 && weight < 1.5)
price = 5.9 + 1 + 1;
else if (weight >= 1.5 && weight < 2)
price = 5.9 + 1 + 1 + 1;
else if (weight >= 2 && weight < 5)
price = 15;
else if (weight >= 5 && weight < 10)
price = 15 + 5;
else if (weight >= 10 && weight < 15)
price = 15 + 5 + 5;
else if (weight >= 15 && weight < 20)
price = 15 + 5 + 5 + 5;
else if (weight >= 20 && weight < 25)
price = 15 + 5 + 5 + 5 + 5;
else if (weight >= 25 && weight <= 30)
price = 15 + 5 + 5 + 5 + 5 + 5;
else
price = 0;
// <--- Rearranged the output.
std::cout << "\n************************************************";
std::cout << "\nThe Customer Name: " << name;
std::cout << "\nThe Customer Address: " << address;
std::cout << "\nCity: " << city << "\tState: " << state << "\tPostal Code : " << postalcode;
std::cout << "\nThe Customer Phone Number: " << phonenumber;
if (weight > 0 && weight <= 30)
{
std::cout << "\nPRICE: RM " << price;
}
else
{
std::cout << "\nPrice: invalid (Our Weight Limit is 30Kg)";
}
std::cout << "\n************************************************\n";
std::cout << "\n*************************************";
std::cout << "\n\nPROCEED WITH NEW CUSTOMER(Y/ N) : "; // <--- Do not shout!
std::cin >> i;
std::cout << "\n*************************************";
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); // <--- Requires header file <limits>. // <--- Added.
}
return 0;
}
|