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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
|
// Hi, I need some help on my programs. Im trying to do Prepaid balance program
// but there are few things that im stuck in.
// 1. After I main loop for the first time n it shows me the current balance
// that I have, If i select lets say I want to choose calls, and choose
// internet plan how do I calculate my new balance?
// 2. I have errors in displaying my Transaction summary, how do i call the
// function so that i can display the items inside my transaction summary.
// 3. And how do I make sure my balance will never be negative, how do I ensure
// that I cant perform the action if my input is exceeded the balance I have.
#include <iostream>
constexpr double Ini_Bal { 6.66 };
double B1_charges(double minutes);
double B2_charges(double minutes);
double B3_charges(double minutes);
double calculate_call_charges();
double calculate_internet_charges();
double calculate_new_balance(double call_charges,
double sms_charges,
double top_up_charges,
double internet_charges);
double calculate_sms_charges();
double calculate_top_up();
double call_charges_accumulator(double call_charges);
char display_logo();
void display_transaction_summary(double call_duration,
int sms,
double call_charges,
double charges,
double new_balance);
char input_internet_plan();
double input_minutes();
double internet_charge_accumulator(int int_charge);
double minutes_accumulator(double call_duration);
double num_sms_accumulator(int sms);
double sms_charges_accumulator(double charges);
double top_up_accumulator(double top_up);
int input_sms();
void display_call_charges();
void display_internet_charges();
void display_menu();
void display_prepaid_balance();
void display_sms_charges();
void main()
{
// Assign data type and initialization
char sentinel = 'Y';
char resp = display_logo();
if (toupper(resp) == sentinel) {
std::cout << "You've exited.\n";
return 0;
}
display_prepaid_balance();
display_menu();
double call_charges {},
sms_charges {},
top_up_charges {},
internet_charges {},
new_balance {};
int selection;
do {
std::cout << "Selection: ";
std::cin >> selection;
switch (selection)
{
case 1: // Calls
display_call_charges();
call_charges = calculate_call_charges();
break;
case 2: // SMS
display_sms_charges();
sms_charges = calculate_sms_charges();
break;
case 3: // Top Up
top_up_charges = calculate_top_up();
break;
case 4: // Internet Plan
display_internet_charges();
internet_charges = calculate_internet_charges();
default:
// Add controls here!
break;
}
double new_balance = calculate_new_balance(call_charges,
sms_charges,
top_up_charges,
internet_charges);
std::cout << "NEW BALANCE = RM " << new_balance << "\n\n\n";
if (new_balance <= 2) {
std::cout << "Your balance is RM " << new_balance << '\n';
do {
std::cout << "You must have minimum RM2.00 before making any "
"calls or sms. \n";
new_balance += calculate_top_up();
std::cout << "Your balance is RM " << new_balance << '\n';
} while (new_balance <= 2);
}
} while (selection >= 1 && selection <= 4);
// show Transaction Summary
if (selection == 5) {
display_transaction_summary(call_duration, // not declared in this scope
sms, // not declared in this scope
call_charges,
charges, // not declared in this scope
new_balance);
}
}
char display_logo()
{
std::cout << "WELCOME TO TARMOBILE CENTER ~\n"
"Enter any key to continue (Y to exit): ";
char cont;
std::cin >> cont;
return cont;
}
void display_prepaid_balance()
{
std::cout << "\t\t\tYour initial prepaid balance\t: RM " << Ini_Bal << "\n\n";
}
void display_menu()
{
std::cout << "\t\t\t| TARMOBILE Prepaid service (Selection) |\n"
"1. CAL\n"
"2. SMS\n"
"3. TOP UP \n"
"4. INTERNET PLAN\n"
"5. EXIT\n";
}
void display_call_charges()
{
std::cout << "\t\t|The Charge Rates For Calls\n"
" \t\t| Band 1 (first 10 minutes)\t: The charge rate is RM "
<< std::fixed << std::setprecision(2) << BAND1
<< " per minute.\t|\n"
" \t\t| Band 2 (next 10 minutes)\t: The charge rate is RM "
<< std::fixed << std::setprecision(2) << BAND2
<< " per minute.\t|\n"
" \t\t| Band 3 (subsequent minutes)\t: The charge rate is RM "
<< std::fixed << std::setprecision(2) << BAND3
<< " per minute.\t|\n";
}
double calculate_call_charges()
{
double minutes,
call_charges;
do {
minutes = input_minutes();
if (minutes <= 10) { // Band 1
call_charges = B1_charges(minutes);
}
if (minutes > 10 && minutes <= 20) { // Band 2
call_charges = B2_charges(minutes);
}
if (minutes > 20) { // Band 3
call_charges = B3_charges(minutes);
}
std::cout << " \t Charge for this call = RM " << call_charges ;
} while (minutes < 0);
call_charges_accumulator(call_charges);
return call_charges;
}
|