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
|
#include <iostream>
#include <cstdlib>
#include <sstream>
using namespace std;
void EnterDay (char& day, char& day2)
{
do
{
cout << "Enter day : ";
cin >> day >> day2;
day = toupper(day);
day2 = toupper(day2);
if ((day != 'M' || day2 != 'O') && (day != 'T' || day2 != 'U') &&
(day != 'W' || day2 != 'E') && (day != 'T' || day2 != 'H') &&
(day != 'F' || day2 != 'R') && (day != 'S' || day2 != 'A') &&
(day != 'S' || day2 != 'U'))
cout << "Wrong input!\nYou may try again\n" << endl;
}while((day != 'M' || day2 != 'O') && (day != 'T' || day2 != 'U') &&
(day != 'W' || day2 != 'E') && (day != 'T' || day2 != 'H') &&
(day != 'F' || day2 != 'R') && (day != 'S' || day2 != 'A') &&
(day != 'S' || day2 != 'U'));
}
void TestCost(int& duration, int& num, double& call_cost, char& day, char& day2)
{
double billrate1 = 0.40, billrate2 = 0.25, billrate3 = 0.15;
do
{
cout << "\nEnter num : ";
cin >> num;
cout << "\nEnter duration (minutes) : ";
cin >> duration;
if ((day != 'S' && day2 != 'A') &&
(day != 'S' && day2 != 'U') && ((num > 0) && (num < 50)) &&
(duration > 0)){
call_cost = duration * billrate1;
cout.precision(2);
cout.setf(ios::fixed);
cout << "The cost of the call : $" << call_cost;
}
else if ((day != 'S' && day2 != 'A') &&
(day != 'S' && day2 != 'U') && ((num >= 50) && (num <= 100)) &&
(duration > 0)){
call_cost = duration * billrate2;
cout.precision(2);
cout.setf(ios::fixed);
cout << "The cost of the call : $" << call_cost;
}
else if ((day == 'S' && day2 == 'A') &&
(day == 'S' && day2 == 'U') || ((num > 0) && (num <= 200)) &&
(duration > 0)){
call_cost = duration * billrate3;
cout.precision(2);
cout.setf(ios::fixed);
cout << "The cost of the call : $" << call_cost;
}
if (duration < 0)
cout << "\nWrong input, you may try again!";
}while(duration < 0);
}
void EnterTime(char* hour, char* mins)
{
stringstream str, str2;
cout << "\nEnter your time : ";
cin.get(hour, 3); cin.get(mins, 3);
str << hour;
str2 << mins;
int w, x;
str >> w;
str2 >> x;
cout << "\nThe time entered is = " << w << ":" << x << endl;
}
void YesNo (char& select)
{
cout << "\n\nDo you want to continue? ";
cin >> select;
select = toupper(select);
}
int main()
{
char day, day2, select, hour[3], mins[3];
int duration, num;
double call_cost;
do
{
EnterDay(day, day2);
TestCost(duration, num, call_cost, day, day2);
EnterTime(hour, mins);
YesNo(select);
}while (select == 'Y');
return 0;
}
|