Output

Everything semed to be o.k. when I had simple output statemet's in the main. When I tried to incorporate the outputs into a function 'output' (requirement) I got brain freeze.It is the last thing I need besides a loop for requesting if the user wants to go again. Any help appreciated, greatly!








#include <iostream>
#include <cctype>
#include <cmath>
#include <iomanip>

using namespace std;

void display();

void input (char& plan, double& min_used );

double calculate_bill (char read_plan, double read_min_used);

double output(char get_plan, double get_minutes, double bill);
//******************************************************************************
int main()
{

char get_plan, get_plan2;

double get_minutes, get_minutes2, total_bill;



display ();

input (get_plan, get_minutes);

output(get_plan, get_minutes, total_bill);


cout << endl << endl;
system ("PAUSE");
return 0;
}
//******************************************************************************
void display ()
{
cout << "This program will calculate your cell phone bill total based on"
" your choice \nof plans & minutes used\n\n";

cout << "For your choice the following plans are offered.\n\n";

cout << "Code 'F': Our fixed rate plan. Is a flat $150.00 fee for unlimited"
" minutes \n (Note: not available to business)\n\n";

cout << "Code 'M': Our direct per-minute charge plan. Has a charge of $5.00, "
"plus\n 21 cents a minute.\n\n";

cout << "Code 'H': Our Home customer plan is $40.00 for the first 600 minutes,"
"\n plus 19 cents for each aditional minute.\n\n";

cout << "Code 'P': The Home Plus plan is $64.00 for the first 1,000 minutes,\n"
" plus 17 cents for each additional minute.\n\n";

cout << "Code 'B': Our Business plan is $150.00 for up to 2,000 minutes;"
" $210.00 for\n up to 3,000 minutes, &"
" $240.00 if over 3,000 minutes.\n\n";
}

//******************************************************************************
void input ( char& plan, double& min_used )
{


cout << "Which plan(s) would you like: \n\n";

cin >> plan;
cout << endl;
plan = toupper(plan);

while ((plan != 'F') && (plan != 'M') && (plan != 'H') &&(plan != 'P') &&
(plan != 'B' )){

cout << "Error-- Wrong character; Please choose from the plans above\n\n";
cin >> plan;
plan = toupper(plan);
}
if (plan != 'F' && plan != 'f'){

cout << "how many minutes used: \n\n";

cin >> min_used;
cout << endl;

while (min_used < 0){

cout << "Error-- Invalid Input; must be 0 or greater.\n";
cout << "Try again: \n";

cin >> min_used;
}
}
}

//******************************************************************************
double calculate_bill (char calc_plan, double calc_min)
{

const double FLAT = 150.0, DIRECT = 5.0, HOME_CUST = 40.0, HOME_PLUS = 64.0,
B1 = 150.0, B2 = 210.0, B3 = 240.0;

double bill;

switch (calc_plan)
{
case 'F':
bill = FLAT;
break;

case 'M':
bill = DIRECT + (.21 * calc_min);
break;

case 'H':
if (calc_min <= 600)
bill = HOME_CUST;
else
bill = HOME_CUST + (.19 * (calc_min - 600));

break;

case 'P':
if (calc_min <= 1000)
bill = HOME_PLUS;
else
bill = HOME_PLUS + (.17 * (calc_min - 1000));

break;
case 'B':
if (calc_min <= 2000)
bill = B1;
else if (calc_min <= 3000)
bill = B2;
else
bill = B3;
break;

}
return bill;
}

//******************************************************************************

double output(char get_plan, double get_minutes, double bill)
{


bill = calculate_bill (get_plan, get_minutes);

cout << fixed << showpoint << setprecision(2);

cout << "The total of your minutes is: " << static_cast<int>(get_minutes) << " min \n\n";
cout << "The plan you chose was: " << get_plan << "\n\n";
cout << "Your total bill is: " << bill << "\n\n";

}
Last edited on
Oops I think I got it!! Thanks anyway.
Topic archived. No new replies allowed.