Need help with switch

Mar 1, 2016 at 3:39am
So I'm trying to write a program that will determine how much someone has for a phone bill for a project for my C++ class and I cannot for the life of me figure out what is wrong with my last switch statement. Can somebody help me please?



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

using namespace std;

int main()
{
int accoutnnumber = 0 ;
char servicetype ;

cout << "Please enter your account number." ;
cin >> accoutnnumber ;

cout << "please enter the type of service you have. Either 'R' for regular service or 'P' for premium service." ;
cin >> servicetype ;


if (servicetype == 'R' || servicetype == 'r' || servicetype == 'P' || servicetype == 'p')
{

}

else
{
cout << "Please enter a valid account types." ;
return 0 ;
}


if (servicetype = 'r')
{
servicetype = 'R' ;
}

if (servicetype = 'p')
{
servicetype = 'P' ;
}

switch (servicetype)
{
case 'R' :
{
const double cost = 6 ;
const double addcost = .2 ;
const int minutes = 50 ;
double addminutes = 0 ;
int minutesused = 0 ;
int totalminutes = 0 ;
double extracost = 0 ;
double totalcost = 0 ;

cout << "Please enter the number of minutes used." << endl ;
cin >> minutesused ;


if (minutes - minutesused >= 0)
{
totalminutes = minutes - minutesused ;

cout << "Your account number is " << accoutnnumber << "." << endl;
cout << "You have a regular user acount." << endl;
cout << "You have used " << totalminutes << " minutes." << endl;
cout << "Your amount due is $6.00" << endl ;

}

else
{
addminutes = minutesused - minutes ;
totalminutes = minutes + addminutes ;
extracost = addminutes * addcost ;
totalcost = cost + extracost ;


cout << "Your account number is " << accoutnnumber << "." << endl;
cout << "You have a regular user acount." << endl;
cout << "You have used " << totalminutes << " minutes." << endl;
cout << "Your amount due is " << setprecision(2) << fixed << totalcost << endl ;
}
break ;
}

case 'P' :
{
const double cost = 15 ;
const double addcost = .1 ;
const double nightcost = .05 ;
const int minutes = 75 ;
const int nightminutes = 100 ;
double addminutes = 0 ;
double addnightminutes = 0 ;
double extracost = 0 ;
int totalminutes = 0 ;
double totalcost = 0 ;
char night ;
int minutesused = 0 ;
int nightminutesused = 0 ;
int totalnightminutes = 0 ;


cout << "Please enter the number of minutes used." << endl ;
cin >> minutesused ;
cout << "Were any night minutes used? Please enter 'Y' or 'N'." << endl ;
cin >> night ;

if (night = 'n')
{
night = 'N' ;
}

if (night = 'y')
{
night = 'Y' ;
}

switch (night)
{
case 'N' :
{

if (minutes - minutesused >= 0)
{
totalminutes = minutes - minutesused ;

cout << "Your account number is " << accoutnnumber << "." << endl;
cout << "You have a premium user acount." << endl;
cout << "You have used " << totalminutes << " minutes." << endl;
cout << "Your amount due is $15.00" << endl ;

}

else
{
addminutes = minutesused - minutes ;
totalminutes = minutes + addminutes ;
extracost = addminutes * addcost ;
totalcost = cost + extracost ;


cout << "Your account number is " << accoutnnumber << "." << endl;
cout << "You have a premium user acount." << endl;
cout << "You have used " << totalminutes << " minutes." << endl;
cout << "Your amount due is " << setprecision(2) << fixed << totalcost << endl ;
}
break ;
}
}
{
case 'Y' :
{
cout << "please enter the total number of night minutes used." ;
cin >> nightminutesused ;

if (minutes - minutesused >= 0 && nightminutes - nightminutesused >=0 )
{
totalminutes = minutes - minutesused ;
totalnightminutes = nightminutes - nightminutesused ;

cout << "Your account number is " << accoutnnumber << "." << endl;
cout << "You have a premium user acount." << endl;
cout << "You have used " << totalminutes << " minutes and "<< totalnightminutes << " night minutes." << endl;
cout << "Your amount due is $15.00" << endl ;
}

else
{
addminutes = minutesused - minutes ;
addnightminutes = nightminutesused - nightminutes ;
totalminutes = minutes + addminutes ;
totalnightminutes = nightminutes + addnightminutes ;
extracost = (addminutes * addcost) + (addnightminutes * nightcost) ;
totalcost = extracost + cost ;

cout << "Your account number is " << accoutnnumber << "." << endl;
cout << "You have a premium user acount." << endl;
cout << "You have used " << totalminutes << " minutes and "<< totalnightminutes << " night minutes." << endl;
cout << "Your amount due is " << setprecision(2) << fixed << totalcost << endl ;
}
break ;
}
break ;
}
}

}

return 0 ;
}
Mar 1, 2016 at 12:15pm
1) Please use code tags when posting code, to make it readable:

http://www.cplusplus.com/articles/z13hAqkS/

2) Why do you think there's something wrong with it? If there's a problem that you're seeing, then tell us what the problem is. Don't make us jump through hoops and have to guess.
Mar 1, 2016 at 3:40pm
indent your code and then you will see the problem.
Topic archived. No new replies allowed.