The code I wrote is supposed to show the billing amount. It compiles fine and gives no runtime errors but fails to provide any output and gives the "Improper selection. Please Choose R or P" error regardless of what letter is typed.
//switch statements
//The program compiles fine and does not give any error messages when run but
//it seems that the switch statement doesn't run the functions
#include <iostream>
using namespace std;
double getAcctNumber (double acctNumber);
char getServiceCode (char serviceCode);
int regularPlan ();
int premiumPlan ();
int main ()
{
double acctNumber;
char serviceCode;
double totalCost;
int totalMinutes;
getAcctNumber (acctNumber);
getServiceCode (serviceCode);
switch (serviceCode)
{
case 'R':
case 'r':
regularPlan ();
break;
case 'P':
case 'p':
premiumPlan ();
break;
default:
cout <<"Error: Improper selection. Please Choose R or P";
return 0;
}
cout <<"Your account number is"<< acctNumber;
cout <<"Your total bill for "<< totalMinutes <<" minutes is $"<< totalCost;
return 0;
}
double getAcctNumber (double acctNumber) //Asks for acct number
{
cout << "Please enter your account number: ";
cin >> acctNumber;
return acctNumber;
}
char getServiceCode (char serviceCode) //Asks for service code
{
cout << "Please enter your service code: ";
cin >> serviceCode;
return serviceCode;
}
int regularPlan () //Calculates plan for regular service
{
int totalMinutes;
double totalCost;
cout <<"Type the number of totalMinutes:";
cin>> totalMinutes;
if ( totalMinutes > 50)
{
totalCost = (totalMinutes - 50) * .20 + 10.00;
}
else
{
totalCost = 10.00;
}
return totalMinutes;
return totalCost;
}
int premiumPlan () //Calculates plan for premium service
{
int dayMinutes;
int nightMinutes;
int totalMinutes;
double totalCost;
double costDay;
double costNight;
cout <<"Please enter the number of day minutes used:";
cin >> dayMinutes;
cout <<"Please enter the number of night minutes used:";
cin >> nightMinutes;
if (dayMinutes > 75)
{
costDay = (dayMinutes - 75) * .10;
}
else
{
costDay = 0;
}
if (nightMinutes > 100)
{
costNight = (nightMinutes - 100) * .05;
}
else
{
costNight=0;
}
totalCost = 25.00 + costDay + costNight;
totalMinutes = dayMinutes + nightMinutes;
return totalMinutes;
return totalCost;
}