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
|
#include <iostream>
#include <cctype> // <--- For std::tolower() and std::toupper().
//#include <cmath> // <--- As of now I have not fould where this header file is needed. Maybe for the future?
//using namespace std; // <--- Best not to use.
int main()
{
constexpr int MAGIC_NUMBER1{ 27 };
constexpr int MAGIC_NUMBER2{ 162 };
constexpr int MAGIC_NUMBER3{ 662 };
int period, New_amount{}, RM27{}, RM162{ 162 }, RM662{}, RM34{}, RM204{}, RM284{}, RM276{}, RM1136{};
char choice, range{}; // , X{}, Y{}, Z{}, Q{}, W{}, E{}, R{}, T{}, U{}, P{}, M{}, N{}, O{}; // <--- Not used or needed. Moved "range" here.
std::cout << "\n Class b = B, Class c = C, Class d = D" << std::endl; // <--- Have no idea what this means. You are working "case"s not classes.
std::cout << "\n Please choose one of the class (B,C,D): ";
//std::cin >> choice;
choice = 'B';
choice = std::toupper(choice); // <--- One option.
switch (std::toupper(choice)) // <--- Another option.
{
case 'B':
std::cout << "\n This is class B section " << std::endl; // <--- OK for testing, but not needed.
std::cout << "\n This rential period consist 1 to 6 Days, 7 to 27 Days and 28 to 60 Days ";
std::cout << "\n X = 1 to 6 Days\n Y = 7 to 27 Days\n Z = 28 to 60 Days";
std::cout << "\n Please select the period range carefully (X,Y,Z): ";
//std::cout << "\nThis is class B section " << std::endl;
//std::cout << "\nThis rential period consist 1 to 6 Days, 7 to 27 Days and 28 to 60 Days ";
//std::cout << "\n1 to 6 Days = X, \n7 to 27 Days = Y, \n28 to 60 Days = Z ";
//std::cout << "\nPlease select the period range carefully (X,Y,Z): ";
std::cin >> range;
range = std::toupper(range); // <--- Here I think this is the best usage.
if (range == 'X')
{
std::cout << "\nYou have enter the 1 to 6 Days range " << std::endl;
std::cout << "\nPlease insert your rential period: "; // <--- Still have no idea what should be entered here.
std::cin >> period;
New_amount = (MAGIC_NUMBER1 * period); // <--- Changed from "==" to "=". You need to set "New_amount" equal to the calculation not chech if it is equal to.
std::cout << "\nPROCESSING ...... PLEASE WAIT "; // <--- This looks nice, but the processing time is so short that it does not mean much.
std::cout << "\nThis is the amount you have to pay:RM " << New_amount;
//break; // <--- You could put break a statement here and in the else if statements. In a do/while loop it would leave the loop.
}
else if (range == 'Y')
{
std::cout << "\n You have enter the 7 to 27 Days range " << std::endl;
std::cout << "\n 7 Days ---> " << RM162;
std::cout << "\n Additional 1 Days ---> + RM25 \n";
std::cout << "\n Please insert your rential period : ";
std::cin >> period;
New_amount = (MAGIC_NUMBER2 + period);
std::cout << "\n This is the amount you have to pay:RM " << New_amount;
}
else if (range == 'Z')
{
std::cout << "\n You have enter the 28 to 60 Days range " << std::endl;
std::cout << "\n 28 Days ---> RM662 ";
std::cout << "\n Additional 1 Days ---> +RM23 ";
std::cout << "\n Please insert your rential period : ";
std::cin >> period;
New_amount = (MAGIC_NUMBER3 + period);
std::cout << "\n This is the amount you have to pay:RM " << New_amount;
}
else
std::cout << " INVALID PERIODS "; // <--- If you reach here it would be nice to start over and be able to enter a correct range. A do/while loop would work.
break;
|