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
|
#include <iostream>
#include <string>
using namespace std;
void welcomeMsg()
{
cout << "Welcome to My Program" << endl << "The program going to calculate the cost of each call you made" << endl;
}
double phoneCost(int& callTime, int& callLength)
{
int noOfCalls;
double totalCost;
// calculating the price of phone call
totalCost = (callLength * 0.10);
if ((callTime < 800) || (callTime > 1800))
{
totalCost = totalCost - (totalCost * 0.5);
}
if (callLength > 60)
{
totalCost = totalCost - (totalCost * 0.15);
}
totalCost = totalCost + (totalCost * 0.04);
return totalCost;
}
int main()
{
welcomeMsg();
cout << endl;
int accountNum, zipCode, numberOfCalls, callTime, callLength;
string userName, address, state, city;
double totalCost;
cout << "Please enter your name: ";
getline(cin, userName, '\n');
cout << "Please enter your account number: ";
cin >> accountNum;
cout << "Please enter your address: ";
getline(cin, address, '\n');
cout << endl << "city: ";
getline(cin, city, '\n');
cout << "State: ";
cin >> state;
cout << "Zip code: ";
cin >> zipCode;
cout << "How many calls do you want to calculate the cost for: ";
cin >> numberOfCalls;
for (int j = 0; j < numberOfCalls; j++)
{
do
{
cout << "Please enter the time of the call as (hhmm) e.g (1800) for (6:00 PM) : ";
cin >> callTime;
if ((callTime < 0) || (callTime > 2359))
{
cout << "Invalid time entered, please reenter valid time";
}
} while ((callTime < 0) || (callTime > 2359));
}
for (int k = 0; k < numberOfCalls; k++)
{
do
{
cout << "Please enter the length of the call as number of minutes: ";
cin >> callLength;
if (callLength < 0)
{
cout << "Invalid call length, please reenter valid one";
}
else if (callLength > 400)
{
cout << "Invalid call length, Longest call phone is 400 minutes please reenter valid one";
}
} while ((callLength < 0) || (callLength > 400));
}
for (int b = 0; b < numberOfCalls; b++)
{
totalCost = phoneCost(callLength, callTime);
}
cout << endl << "The total cost of your call is: " << totalCost << "$" << endl;
system("PAUSE");
return 0;
}
|