Alright, I have edited some of the code, so now the question is how it calculates the right final total? I am working on the regular service, and I want it to subtract the 50 free minutes first, then add the extra minutes the user has overused, then multiply the extra minutes by $0.20 and make that into the finaltotal.
And if I have any more mistakes please tell me. I know I have made a lot of mistakes, sorry!
I have a project to do, and here is the requested functionalities list:
Prompts the user to enter an account number, a service code, and the number of minutes the service was used.
Regular: Values are “R” and “r”:
$10.00/month
First 50 min. are free
Charges for over 50 min. are $0.20 per min.
Premium: Values are “P” and “p”:
$25.00/month plus:
Calls between 6 - 18 first 75 min are free, after that they’re $0.10 per min
Calls between 18 - 6 first 100 min are free, after that they’re $0.05 per min
If any other character is used then display an error message
Calculate the total and print the bill (display it out)
This is my code:
#include <iostream>
using namespace std;
int main()
{
// VARIABLES //
int accnum, minnum, minnumm;
double total, finaltotal, grandtotal, finaltotall;
char scode;
cout << "Hello, thank you for paying your phone bill." << ends;
cout << endl;
cout << endl;
cout << "Please enter your account number: ";
cin >> accnum ; //Enter some number
cout << "Please enter your service code (r as regular service or p for premium service): ";
cin >> scode ; //Enter R or r for regular service and P or p for premium service
////////////// THIS IS FOR REGULAR SERVICE //////////////
if (scode == 'R' || scode == 'r') { // Values for Regular service
cout << "This service provides 50 minutes for phone calls for 50 minutes for free for $10.00 a month, and charge $0.20 every minute over 50 minutes." << endl;
cout << "How many minutes have you used up?: ";
cin >> minnum;
if (minnum > 50) {
total = minnum * .20;
finaltotal = total + 10;
cout << "You have made phone calls over 50 minutes, your total will be " << finaltotal << "." << endl;
cout << "Your account number is " << accnum << " , with a Regular service. You have used " << minnum << "/50 minutes. Your total is $" << finaltotal << " . Thank you for your time." << endl; //Displays the acc. #, type of service, # of min the phone service used, and amount due from user
cout << endl;
} else {
cout << "You have not made phone calls over 50 minutes, your total will be $" << finaltotal << "." << endl;
cout << "Your account number is " << accnum << " , with a Regular service. You have used " << minnum << "/50 minutes. Your total is $" << finaltotal << " . Thank you for your time." << endl; //Displays the acc. #, type of service, # of min the phone service used, and amount due from user
}
////////////// THIS IS FOR PREMIUM SERVICE //////////////
} else if (scode == 'P' || scode == 'p') { //Values for Premium service
cout << "This service provides your first 75 minutes phone calls from 6:00 - 18:00, and charge $0.10 for every minute over. Your first 100 minutes for phone calls from 18:00 - 6:00 are free, and charge $0.05 for every minute over." << endl;
cout << "How many minutes have you used up between 6:00 - 18:00? "; //Time between 6am - 6pm
cin >> minnumm;
if (minnumm > 75) { //If # of minutes is over 75
total = minnumm * .10; //Then it multiplies total * $.10
finaltotall = total + 25; //Then adds the $10/month
cout << "You have made phone calls over 75 minutes, your total will be $" << finaltotall << "." << endl;
} else {
cout << "How many minutes have you used up between 18:00 - 6:00? "; } //Time between 6pm - 6am
cin >> minnum;
if (minnum > 100) { //If # of minutes is over 100
total = minnum * .05; //Then it multiplies total * $.05
finaltotal = total + 25;
//Then adds the $25/month
cout << "You have made phone calls over 100 minutes, your total will be $" << finaltotal << "." << endl;
grandtotal = finaltotall + finaltotal; //Calculates both the 6am-6pm and 6pm-6am totals together
cout << "Your account number is " << accnum << " , with a Premium service. You have used " << minnumm << "/75 minutes from 6:00-18:00. You have used" << minnum << "/100 from 18:00-6:00. Your total is $" << grandtotal << " . Thank you for your time." << endl; //Displays the acc. #, type of service, # of min the phone service used, and amount due from user
} else {
cout << "You have not made phone calls over 100 minutes, your total will be $" << finaltotal << "." << endl;
cout << "Your account number is " << accnum << " , with a Premium service. You have used " << minnumm << "/75 minutes from 6:00-18:00. You have used " << minnum << "/100 from 18:00-6:00. Your total is " << grandtotal << " . Thank you for your time." << endl;
cout << endl;
cout << endl; } //Displays the acc. #, type of service, # of min the phone service used, and amount due from user
////////////// THIS IS IF THEY TYPED IN ANY LETTER OTHER THAN R, r, P, p //////////////
} else { //If user doesn't type P or R, then this is error message
cout << "Sorry, that service does not exist. Please try again." << endl;
cout << endl; }
system("pause");
return 0;
}
As far as I can see (and people in follow-up answers might find more errors), the glaring issue is that you have used the AND operator instead of the OR operator.
This statement:
if (scode == 'R' && scode == 'r') { // Values for Regular service
Should be:
if (scode == 'R' || scode == 'r') { // Values for Regular service
Similarly, this statement:
if (scode == 'P' && scode == 'p') { //Values for Premium service
Should be:
if (scode == 'P' || scode == 'p') { //Values for Premium service
A variable can't match two different values at the same time, so the if blocks will never be entered when using && instead of ||.
Related
This code is designed to take an order, add that to the total_price variable, apply discounts based on the total price, then add a tip and echo all the information back to the user.
For some reason when I run the code, it isn't taking input from the user. I think it's related to the while statement but it outputs that my total_price is 0 after entering integers.
The tip calculation at the bottom isn't working correctly. It prompts the user to enter a tip value, but then skips to the end and says the final total is 0, without the user being able to enter any tip.
Thanks so much for the help!!
#include <iostream>
using namespace std;
int main()
{
int total_price{0}; // This variable will contain the price for all orders
int tip{0};
int discount_total{0};
int tip_total = tip + discount_total;
cout << "Welcome!\nThis program is designed to help take your order.\n";
cout << "Our discounts availible today are: \n10 percent off orders over $50, and 5 percent off orders between $25 and $50.\n";
// This is where the user is prompted to enter the price of their order
cout << "Please enter the price of your item: ";
cin >> total_price;
// No negative numbers will be accepted
if (total_price <= 0)
{
cout << "Invalid number, please re-enter the price of your item: ";
}
// User can continue ordering unless typing No
while (total_price > 0)
{
cout << "Is there anything else? If not type No: ";
cin >> total_price;
}
// Once the user types No, it brings them to the tip section
// Marks the end of the order
if ("No")
{
cout << "Thank you. Your total price is " << total_price << endl;
}
// Discount modifications
if (total_price >= 50)
{
discount_total = total_price * .05;
cout << "Your new total is " << discount_total << " with the 10 percent discount.\n";
}
else if (total_price >= 25 && total_price <= 50)
{
discount_total = total_price * .05;
cout << "Your new total is " << total_price << " with the 5 percent discount.\n";
}
else
{
total_price = discount_total;
cout << "Your total is the same, " << total_price << "\n";
}
// Tip calculation
cout << " Feel free to add a tip! Please enter here: ";
cin >> tip;
if (tip > 0)
{
cout << "Your final total is: " << tip_total << " dollars";
}
else if (tip < 0)
{
cout << "Your tip is invalid, please enter a valid tip: ";
}
return 0;
}
My objective is to calculate and output a loan repayment schedule. The thing I would like to get help on is putting the principles added to the equation and printing out the repayment schedule. I am not sure if I did the calculations right as I have not had a personal finance class yet, and still get to grasp the concept of loans.
The loan repayment schedule is based on full price of an auto, their interest rate and their payment, assuming no money is put down. All fees and taxes are included in the price and will be financed. I also have to out put the repayment schedule to both the screen and a file - one month per line. . If the user has a credit rate of 800, they get a 3% annual interest rate; 700+ gets 5% interest rate; 600+ get 7% interest rate; and less than 600 get 12% interest rate
The credit scores for 700, 600, and below 600 are left blank because I am just going to copy the 800 credit score part again but change the interest rates.
// This program calculates a loan depending on the pereson's credit score
// how much they can pay per month. It almost outputs the month, principal,
// payment, interest, and the money that's been applied
#include <iostream>
#include <cstdio>
#include <iomanip>
using namespace std;
int main() {
int month = 0, creditScore = 0, whichCar;
double principle, payment = 0.0, interestPaid, applied, interestRate;
cout << fixed << setprecision(2) << showpoint; // Sets total or whatever to 2 decimal points
cout << "---------------------------------------------" << endl; // Displays welcome banner
cout << "| |" << endl;
cout << "| JOLLY GOOD SHOW WE HAVE CARS AYEEE |" << endl;
cout << "| |" << endl;
cout << "---------------------------------------------" << endl;
cout << endl;
cout << "Hey, I see you want a car. You can only purchase one car though." << endl;
cout << endl;
cout << "1. Furawree: $6,969.69" << endl; // Displays menu of autos
cout << "2. Buggee: $420,420.420" << endl;
cout << "3. Sedon: $900" << endl;
cout << "4. Truck: $900,000.90" << endl;
cout << "5. Couppee: $22,222.22" << endl;
cout << endl;
cout << "Which car would you like to purchase?" << endl; // Asks user car type and user inputs car #
cout << "Please enter the number of the car: ";
cin >> whichCar;
cout << endl;
switch(whichCar) { // If user choses a number 1-5, then it asks them how much they can pay each month for the car and their credit score
case 1: // FURAWREE
principle = 6969.69;
break;
case 2: // BUGGEE
principle = 420420.42;
break;
case 3: // SEDON
principle = 900;
break;
case 4: // TRUCK
principle = 900000.90;
break;
case 5: // COUPPEE
principle = 22222.22;
break;
default: // If user doesn't pick a number from 1-5
cout << "Yea uhhmmm we don't have that sorry, go away." << endl;
}
cout << "Please enter how much you can pay each month for this Furawree: ";
cin >> payment;
cout << "Please enter your credit score: ";
cin >> creditScore;
if (creditScore >= 800) {
interestRate = .03 / 12;
do {
interestPaid = principle * interestRate;
applied = payment - interestPaid;
month++;
} while (principle < 0) ;
cout << "Month " << " Principle " << " Payment " << " Interest " << " Applied " << endl;
cout << month << " $" << principle << " $" << payment << " " << interestPaid << " $" << applied << endl;
} else if (creditScore >= 700) {
// Will be copied from the 800 credit score
} else if (creditScore >= 600) {
// Will be copied from the 800 credit score
} else {
// Will be copied from the 800 credit score
}
cout << endl;
cout << endl;
cout << "Your payment: $" << payment << endl;
cout << "Your credit score: " << creditScore << endl;
cout << endl;
cout << endl;
system("pause");
return 0;
}
Mate, you need to fix code under credit - 800.
loop condition is incorrect
cout is after the loop, therefore it will print only once .
principle is not incremented nor decremented . and you are checking if principle is less than 0, however principle is set more than 0. so the loop will execute only once.
you need a fix some thing like this. I have just fine tuned little bit. pls fix the rest
if (creditScore >= 800) {
interestRate = .03 / 12;
cout << "Month " << " Principle " << " Payment " << " Interest " << " Applied " << endl;
cout <<"-------------------------------------------------------" << endl;
do {
interestPaid = principle * interestRate;
applied = payment - interestPaid;
principle = principle - applied;
cout << month << " $" << principle << " $" << payment << " " << interestPaid << " $" << applied << endl;
month++;
} while (principle > 0) ;
} else if (creditScore >= 700) {
Note :-
The above code is not following any object oriented concepts. Its not even functional programming. Introduce classes, methods to reduce headache and it will help to debug.
use \t\t to get spaces instead of spaces.
This code will need a big re-work to make it look professional .
When it runs the winnings or losses are taken or added from the bank and then it is run again the bank is set back to a 25$ bank not the updated bank
int main()
{
srand(time(0));
int bank = 25;
int total;
char answer;
cout << "Come play Spin the Wheel. The wheel has numbers from 1-10." << endl
<< "If you spin an even number you lose that amount. If you spin" << endl
<< "an odd number you win that amount. You start with a 25$ bank." << endl;
cout << "Your bank is $" << bank << ". Would you like to spin the wheel? (y/n):" << endl;
cin >> answer;
while (toupper(answer) == 'Y')
{
int num = rand() % 10 + 1;
if (bank <= 10)
{
cout << "Sorry you must have more than 10$ to play" << endl;
}
else if (num % 2 == 0 )
{
total = bank + num;
cout << "You spun a " << num << " and won $" << num << endl;
cout << "Your bank is now: $" << total << endl;
}
else
{
total = bank - num;
cout << "You spun a " << num << " and lost $" << num << endl;
cout << "Your bank is now: $" << total << endl;
}
cout << "Would you like to play Again (y/n) ?" << endl;
cin >> answer;
}
return 0;
}
When it runs the winnings or losses are taken or added from the bank and then it is run again the bank is set back to a 25$ bank not the updated bank
You initialize bank to be 25 dollar in this function. Inside the while loop only total is updated not bank.
Another problem arises when there is too few money to play. I suppose you would like to display your message one time, but you are stuck inside the loop because it is never broken out of.
I believe your else if and else statements are backwards.
num % 2 == 0
Would signify that the number was even, if true. The instructions say that you lose the money if the number is even.
Bank will never be less than or equal to 10 because you are never setting bank to anything after the initial 25. Its always 25.
The variable total seems redundant. Maybe add or subtract the amount rolled directly from bank.
You need to set
bank = total
else you never change its value
I'm writing a code that takes a user's input and calculates a discount based on how many units the user buys. Here is my problem; I want to use input validation to make sure the number entered is between 0 and 65535 (the max range for an unsigned int) but the way I have this program set up, if the user enters a number outside of this range I'm experiencing overflow/underflow and an incorrect number is stored in the variable before it ever even hits the if/else clauses. I'm new to C++ so please be kind. What can I do to check if this number is in the correct range when the user enters it. Also, is there a way to verify that the user has not entered a character other than a number?
Here is my code:
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
// display the instructions and inform the user of the discounts available
cout << " This software package sells for $99. Discounts are given according to the following list: \n";
cout << "----------------------------------" << endl;
cout << " Quantity\t\t Discount" << endl;
cout << "----------------------------------" << endl;
cout << " 10 - 19\t\t 20%" << endl;
cout << " 20 - 49\t\t 30%" << endl;
cout << " 50 - 99\t\t 40%" << endl;
cout << " 100 or more\t\t 50%" << endl;
cout << "----------------------------------" << endl;
cout << "\n\n";
const double price = 99.00;
unsigned short quantity; // variable to hold the user's quantity.
// shouldn't need more than 2 bytes for this (unsigned short)
cout << "How many units are sold?: ";
cin >> quantity;
double discount; // variable to hold the amount discounted
double total; // to hold the total sales price
cout << fixed << showpoint << setprecision(2); // set the display of numeric values
// calculate the discounted prices
if (quantity >= 1 && quantity <= 9) {
total = quantity * price; // calculate the total without a discount
cout << "There is no discount for this order \n";
cout << quantity << " units were sold at $" << price << " a piece for a total of " << total << endl;
cout << "\n";
}
else if (quantity >= 10 && quantity <= 19) {
discount = (quantity * price) * .20; // calculate the discount
total = (quantity * price) - discount; // calculate the total
cout << "There is a 20% discount \n";
cout << quantity << " units were sold at $" << price << " with a discount of 20% applied to the order. \n";
cout << "The total cost of the sale is $" << total << endl;
cout << "\n";
}
else if (quantity >= 20 && quantity <= 49) {
discount = (quantity * price) * .30; // calculate the discount
total = (quantity * price) - discount; // calculate the total
cout << "There is a 30% discount \n";
cout << quantity << " units were sold at $" << price << " with a discount of 30% applied to the order. \n";
cout << "The total cost of the sale is $" << total << endl;
cout << "\n";
}
else if (quantity >= 50 && quantity <= 99) {
discount = (quantity * price) * .40; // calculate the discount
total = (quantity * price) - discount; // calculate the total
cout << "There is a 40% discount \n";
cout << quantity << " units were sold at $" << price << " with a discount of 40% applied to the order. \n";
cout << "The total cost of the sale is $" << total << endl;
cout << "\n";
}
else if(quantity > 99 && quantity <= 65535) {
// the maximum number allowed in a short int is 65535. I is unrealistic that someone would order more
// units than that so this else if clause checks to make sure the number of ordered items is below this number
discount = (quantity * price) * .50; // calculate the discount
total = (quantity * price) - discount; // calculate the total
cout << "There is a 50% discount \n";
cout << quantity << " units were sold at $" << price << " with a discount of 50% applied to the order. \n";
cout << "The total cost of the sale is $" << total << endl;
cout << "\n";
}
else {
// the trailing else clause is used to catch any value for quantity that is 0 or below or any quantity
// bigger than what a short int can hold.
cout << "You entered an invalid quantity.\n";
cout << "Please enter a value greater than 0 or less than 65,535. \n\n";
}
system("pause");
return 0;
}
The final else clause is only executed when a value of 0 is entered. Here is an example of the output with a value outside the range
This software package sells for $99. Discounts are given according to the following list:
----------------------------------
Quantity Discount
----------------------------------
10 - 19 20%
20 - 49 30%
50 - 99 40%
100 or more 50%
----------------------------------
How many units are sold?: 65600
There is a 50% discount
52428 units were sold at $99.00 with a discount of 50% applied to the order.
The total cost of the sale is $2595186.00
Press any key to continue . . .
So in all honesty, I don't think this is a bad question.
It just deals with error checking whatever comes out of cin >> quantity.
Like described here: User Input of Integers - Error Handling, a way to handle this is to wrap the cin >> quantity with some error handling code like below.
if (cin >> quantity) {
// read succeeded
} else if (cin.bad()) {
// IO error
} else if (cin.eof()) {
// EOF reached (perhaps combined with a format problem)
} else {
// format problem
}
This will not take care of the integer overflows however, so a full solution would be to make quantity an int and use
cout << "How many units are sold?: ";
if (cin >> quantity) {
// read succeeded
// check for range
if (quantity < 0 || quantity > 65535) {
cout << "Number needs to be between 0 and 65535" << endl;
return -1;
}
} else if (cin.bad()) {
// IO error
cout << "Couldn't do a read from stdin :(" << endl;
return -1;
} else if (cin.eof()) {
// EOF reached (perhaps combined with a format problem)
cout << "Stdin gave EOF :(" << endl;
return -1;
} else {
// format problem
cout << "Encountered incorrect format" << endl;
return -1;
}
My assignment is use 3 functions with parameters, as follows:
function calcRegBill – accepts one integer argument for the number of minutes used. Determines and returns the total amount due.
function calcPremBill – accepts two integer arguments, for the number of day minutes and number of night minutes used. Determines and returns the total amount due.
function printBill – accepts 4 arguments: a string account number, a character service code, an integer total number of minutes used, and an amount due. Note that this is a generic print bill function, which prints either a regular or premium bill, using the following format:
Account Number: XXXX
Service Type: Regular (or Premium, depending on the character received)
Total Minutes: XXX
Amount Due: $XXX.XX
Your main function will prompt the user for the account number and service code. Based on the service code, main will ask for the correct number of minutes, then call your functions above as needed to finish the job. In addition you must :
Incorporate a loop in your program to run the bill as many times as needed. You may do this either by a sentinel controlled loop, or with a counter controlled loop.
I already built the program and tested it with everything in the main function of the program. I am just really confused about how to break it into the 3 separate functions and have it all still work. I am a total noob at C++
Here is the program so far, I started to add the functions, but I do not believe they're right.
// Cell Bill Fun
// April 14, 2013
#include <iostream>
#include <iomanip>
using namespace std;
double calcRegBill(int a);
double calcPremBill(int b, int c);
void printBill(string acctNumber, char serviceCode, int d, double e);
int main()
{
//declare variables for question 4
char serviceCode;
int acctNumber;
int minutes;
int dayMinutes;
int nightMinutes;
int charge;
int dayFee;
int nightFee;
double amtDue;
//get input
cout << "Please enter your information to calculate your cell phone bill ";
cout << "What is your account number? (please enter a 4-digit number-example 1234): ";
cin >> acctNumber;
cout << "Do you have regular or premium service? Enter r for regular service, p for Premium.: ";
cin >> serviceCode;
//format output
cout<< setprecision(2) << fixed;
//output
switch (serviceCode)
{
case 'r':{
cout << "How many minutes did you use?: ";
cin >> minutes;
if (minutes <= 50)
amtDue = 10;
else if (minutes > 50)
amtDue=10+((minutes-50)*.20);
else
cout <<"You have input an invalid service code. Please type r for regular or p for premium service." << endl;
cout <<"Cellular Account #:" << acctNumber << endl;
cout <<"Type of Service: Regular" << endl;
cout <<"Total Minutes:" << minutes << endl;
cout <<"Amount Due: $"<< amtDue << endl;}
break;
case 'R':{
cout << "How many minutes did you use?: ";
cin >> minutes;
if (minutes <= 50)
amtDue = 10;
else if (minutes > 50)
amtDue=10+((minutes-50)*.20);
else
cout <<"You have input an invalid service code. Please type r for regular or p for premium service." << endl;
cout <<"Cellular Account #:" << acctNumber << endl;
cout <<"Type of Service: Regular" << endl;
cout <<"Total Minutes:" << minutes << endl;
cout <<"Amount Due: $"<< amtDue << endl;}
break;
case 'p':
cout << "How many daytime minutes did you use?";
cin >> dayMinutes;
if (dayMinutes <= 75)
dayFee = 0;
else if (dayMinutes > 75)
dayFee=((dayMinutes-75)*.10);
cout << "How many night time minutes did you use?";
cin >> nightMinutes;
if (nightMinutes <= 100)
nightFee = 0;
else if (nightMinutes > 100)
nightFee=((nightMinutes-100)*.05);
else
cout <<"You have input an invalid service code. Please type r for regular or p for premium service." << endl;
cout <<"Cellular Account #:" << acctNumber << endl;
cout <<"Type of Service: Premium" << endl;
cout <<"Total Minutes:" <<dayMinutes+nightMinutes << endl;
cout <<"Amount Due: $"<<25<<"+"<<dayFee<<"+"<<nightFee<<"= $"<<25+dayFee+nightFee << endl;
break;
case 'P':
cout << "How many daytime minutes did you use?";
cin >> dayMinutes;
if (dayMinutes <= 75)
dayFee = 0;
else if (dayMinutes > 75)
dayFee=((dayMinutes-75)*.10);
cout << "How many night time minutes did you use?";
cin >> nightMinutes;
if (nightMinutes <= 100)
nightFee = 0;
else if (nightMinutes > 100)
nightFee=((nightMinutes-100)*.05);
else
cout <<"You have input an invalid service code. Please type r for regular or p for premium service." << endl;
cout <<"Cellular Account #:" << acctNumber << endl;
cout <<"Type of Service: Premium" << endl;
cout <<"Total Minutes:" <<dayMinutes+nightMinutes << endl;
cout <<"Amount Due: $"<<25<<"+"<<dayFee<<"+"<<nightFee<<"= $"<<25+dayFee+nightFee << endl;
break;
default:
cout << "Invalid Service Code. Enter r for regular service, p for Premium.";
}
return 0;
}
double calcRegBill(int a)
{
}
double calcPremBill(int b, int c)
{
}
void printBill(string acctNumber, char serviceCode, int d, double e )
{
return;
}
Functions work by requesting data (the parameters you pass to them), and operating on this data, often by returning data.
For example, in the case 'r': block, instead of of your code, you would want to have:
cout << "How many minutes did you use?: ";
cin >> minutes;
amtDue = calcRegBill(minutes);
cout <<"Cellular Account #:" << acctNumber << endl;
cout <<"Type of Service: Regular" << endl;
cout <<"Total Minutes:" << minutes << endl;
cout <<"Amount Due: $"<< amtDue << endl;}
break;
Then, you can move the code that was previously in main to calculate amtDue into the calcRegBill() function, like this:
double calcRegBill(int minutes)
{
double bill;
if (a < 50)
bill = 10;
else
bill = 10+((minutes-50)*.20);
return bill;
}
The key here is that instead of calculating amtDue in the main function, you calculate it in the calcRegBill function and return it to the main function. Also, notice that I changed the name of the parameter from a to minutes. This improves clarity of its purpose in the function.
The general structure of your program is mostly correct, and I am not really sure what you are asking.
For trouble shooting, write one of your functions and test it without all the other stuff. For example, write calcRegBill...
Then write a very simple main:
int main() {
cout << calcRegBill(3) << endl;
cout << calcRegBill(11) << endl;
}
Did you get the values expected? If so then move on to the next function. Development is often about breaking the problem down into smaller manageable problems.
You need to break down the flow of what you're doing.
First, you gather information. Note: The information you're looking for is the same, regardless of whether it's a premium or regular bill. You don't need to branch so early.
In order to calculate their bill, you branch based on premium or regular. Either way, you get back a double from this, so you can have a double variable that you store the return from calcRegBill or calcPremBill into. Declare this double variable before the branch, assign to it inside of your two branches (regular or premium).
Then, when you call printBill, you can pass this value and what type of bill it was.