#include <iostream>
#include <fstream>
#include <string>
using namespace std;
const double PRICEA = 9.95;
const double PRICEB = 14.95;
const double PRICEC = 19.95;
const int ONE = 10;
const int TWO = 20;
const double EXTRA1 = 2.00;
const double EXTRA2 = 1.00;
int main()
{
int hours;
char pkgType;
double cost;
ifstream infile;
infile.open("pa5.input");
if(infile.fail())
{
cout<<"Error Opening File." <<endl;
exit(1);
}
infile >> pkgType >> hours;
while (infile)
{
switch (pkgType)
{
case 'A':
if (hours > ONE )
cout << "Package A " << PRICEA << hours
<< cost << endl;
cost = PRICEA + ((hours - ONE) * EXTRA1);
break;
else if (hours <= ONE)
{
cout << "Package A " << PRICEA << hours
<< cost << endl;
cost = PRICEA;
}
break;
case 'B':
if (hours > TWO )
{
cout << "Package B "<< PRICEB << hours
<< cost << endl;
cost = PRICEB + ((hours - TWO) * EXTRA2);
}
break;
else if
{
cout << "Package B "<< PRICEB << hours
<< cost << endl;
cost = PRICEB;
}
break;
case 'C':
cout <<"Package C "<< PRICEC << hours
<< cost << endl;
cost = PRICEC;
break;
default: cout << endl << "Invalid Package Type! " << endl;
}
}
system("pause");
return 0;
}
Amanda21 0 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.