I'm working on this program, and when i run it for 'p', 'P', or for a incorrect service code a error message pops up saying that "totalCost is being used without being initialized"
I don't want to change it to switches, case, and breaks now because I've come too far to change it all.
I have that variable right here just below. So whats wrong?
#include <iomanip>
#include <iostream>
using namespace std;
cout << "Enter your Account Number: " << endl;
cin >> acctCode;
cout << "Enter your Service Code: " << endl;
cin >> serviceCode;
if (serviceCode =='r' || serviceCode == 'R')
{
cout << "How many minutes have you used: " << endl;
cin >> minsUsed;
if (minsUsed > 50)
{
totalCost = 10 + ((minsUsed-50) * .20);
}
else
{
totalCost = 10;
}
}
else if ( serviceCode == 'p' || serviceCode == 'P')
{
cout << "How many day minutes have you used:" << endl;
cin >> minsDay;
cout << "How many night minutes have you used: " << endl;
cin >> minsNight;
What if someone selects P and enters over 75 minutes for day and less than 100 minutes for night? or vice versa - under 75 minutes for day, but more than 100 minutes for night? Just wondering if they're supposed to get a pass on being over on one of the minute types if they're under on the other.
I'd probably validate the service code right after they enter it, before starting all the calculations. So if they've entered an invalid code, they can try again.