Help with if else statement

closed account (z8q4izwU)
Hello, im learning functions and doing a program for class. It compiles but it doesnt hit my if statements can any one help me with this?




#include <iostream>
#include <iomanip>

using namespace std;

// Named constants

const double REGULAR_SERV_CHARGES = 10.00;
const double REGULAR_FREE_MINUTES = 50;
const double REGULAR_RATES_OVER_50 = 0.20;

const double PREMIUM_SERV_CHARGES = 25.00;
const double PREMIUM_FREE_DAY_MINUTES = 75;
const double PREMIUM_DAY_RATES_OVER_75 = 0.10;

const double PREMIUM_FREE_NIGHT_MINUTES = 100;
const double PREMIUM_NIGHT_RATES_OVER_100 = 0.05;

double regular (); // function prototype
double premium (); // function prototype

int main()
{
int accountNumber;
char serviceType;
int minutesUsed;
double amountDue, daytimeMinutesUsed, nighttimeMinutesUsed;

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

cout << "Enter account number: ";
cin >> accountNumber;
cout << endl;

cout << "Enter a service code for the type of service owned: "
<< " R or r (Regular), "
<< " P or p (Premium): ";
cin >> serviceType;
cout << endl;

switch (serviceType)
{
case 'R':
case 'r':

amountDue = regular ();
cout << "Account number: "
<< accountNumber
<< endl;
cout << "Amount due: $"
<< amountDue
<< endl;

break;

case 'P':
case 'p':
amountDue = premium ();
cout << "Account number: "
<< accountNumber
<< endl;

cout << "Amount due: $"
<< amountDue
<< endl;

break;
default:
cout << "Invalid customer type." << endl;
}
system("pause");
return 0;
}


double regular () //regular
{
int minutesUsed;
double amountDue;
double bAmount; //billing amount

cout << ("Enter amount of minutes used: ");
cin >> minutesUsed;
cout << endl;
if (minutesUsed <= REGULAR_FREE_MINUTES)
amountDue = REGULAR_SERV_CHARGES;
else
amountDue = REGULAR_SERV_CHARGES
+ (minutesUsed - REGULAR_FREE_MINUTES)
* REGULAR_RATES_OVER_50;
return bAmount;
}


double premium () //Premium
{
int daytimeMinutesUsed;
int nighttimeMinutesUsed;
double amountDue;
double bAmount;

cout << ("Enter the amount of daytime minutes used: ");
cin >> daytimeMinutesUsed;
cout << endl;

cout << ("Enter the amount of night time minuets used: ");
cin >> nighttimeMinutesUsed;
cout<< endl;

if ((75 - daytimeMinutesUsed) > 0)
amountDue += .10 * (75 - daytimeMinutesUsed);

else
amountDue = PREMIUM_SERV_CHARGES
+ (daytimeMinutesUsed - PREMIUM_FREE_DAY_MINUTES)
* PREMIUM_DAY_RATES_OVER_75;

if (nighttimeMinutesUsed <= PREMIUM_FREE_NIGHT_MINUTES)
amountDue = PREMIUM_SERV_CHARGES;

else
amountDue = PREMIUM_SERV_CHARGES
+ (nighttimeMinutesUsed - PREMIUM_FREE_NIGHT_MINUTES)
* PREMIUM_NIGHT_RATES_OVER_100;
return bAmount;
}


I don't see any reason your if statements wouldn't be executed. Have you confirmed this in a debugger by stepping through them?

What I do see is you are returning uninitialized variables (bAmount) from both the regular() and premium() functions.

PLEASE USE CODE TAGS (the <> formatting button) when posting code. It makes it easier to help you.
Topic archived. No new replies allowed.