Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6700597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:50:01+00:00 2026-05-26T06:50:01+00:00

When i run the program and select premium it runs it put then it

  • 0

When i run the program and select premium it runs it put then it also runs the function for regular service. the problem is in int main at the lines. What did i do wrong? IT says i didnt explain the problem clearly enough, not sure why so here is more text to get around that.

premiumserv = premserv(daymin, nightmin); 
regularserv = regserv ();

Full code below

/************************************************/
/* Author:     Sam LaManna                      */
/* Course:     CSC 135 Lisa Frye                */
/* Assignment: Program 3 Cell Phone Bill        */
/* Due Date:   10/20/2011                       */
/* Filename:   program3.cpp                     */
/* Purpose:    This program calculates and      */
/*             prints the bill for a cellular   */
/*             telephone company                */
/************************************************/



//TODO:
//Fix account number issue: large numbers cause intfinte loop. Maybe use string?
//Complete premium and regular service calculation functions
//Output function - Figure out how to print 



#include <iostream>    //Basic input/output
#include <iomanip>     //Manipulators 

using namespace std;

void instruct();       //Function declaration for printing instructions
int accnum ();         //Function declaration for account number
char servcode ();      //Function declaration for service code
float regserv ();      //Function declaration for regular service
float premserv (int& daymin, int& nightmin);     //Function declaration for premium service
void output (float premiumserv, float regularserv);        //Function declaration for printing results

int main()
{
  int accountnum = 0;     //Var for account number
  char servicecode = 'a';     //Var for service code
  float premiumserv = 0;      //Var for premium service total
  float regularserv = 0;      //Var for regular service total
  int daymin = 0;
  int nightmin = 0;

  instruct();     //Function call to print instructions

  accountnum = accnum();     //Function call to input account number

  servicecode = servcode();  //Function call to get service code

  switch(servicecode)        //Switch to determine which calc to use
    {
    case 'r':
      break;
    case 'R':
     regserv ();
      break;
    case 'p':
      break;
    case 'P':
     premserv (daymin, nightmin);
      break;
    }

  premiumserv = premserv ( daymin, nightmin);     //Function call for regular service

   regularserv = regserv ();      //Function call for premium service

  cout <<"total" << premiumserv <<"day" << daymin << "night " << nightmin;

  return 0;
}



/************************************************/
/* Name: instruct                               */
/* Description: Prints instructions to user     */
/* Parameters: N/A                              */
/* Return Value: N/A                            */
/************************************************/

void instruct()
{
  cout << "\n" <<  "This program will calculate the cellular telephone bill for a given customer when " << "\n" 
       << "given the correct inputs. ";
  //Prints instructions to user

  return;
}

/************************************************/
/* Name: accnum                                 */
/* Description: Get user account number         */
/* Parameters: N/A                              */
/* Return Value: accnum                         */
/************************************************/

int accnum()
{
  int accnum = 0;                               //Define var for account number
  char accyn = 'n';                             //Define char for user verify
  int i = 1;                                    //Define var for sentinel loop


  do {
    cout << "\n" << "\n" << "Please enter your account number: ";
    cin >> accnum;
    while ((accnum < 0) && (i<3))
      {
    cout << "\n" << "Error - invalid number, please try again.";
    cout << "\n" << "Please enter your account number: ";
    cin >> accnum;
    i++;
    if (i == 3)
      {
        cout << "\n" << "Too many invalid attempts, program terminating." << "\n"
         << "Have a nice day. " << "\n" << "\n";
        exit (0);
      }     //end if
      }     //end while
    cout << "\n";
    cout << "Your account number is: " << accnum << "\n"
     << "Is this correct? [y/n] ";
    cin >> accyn;
  } while (accyn != 'y');     //end do/while loop


  return accnum;
}

/************************************************/
/* Name: servcode                               */
/* Description: Get service type                */
/* Parameters: N/A                              */
/* Return Value: servcode                       */
/************************************************/

char servcode()
{
  char servcode = 'a';                             //Define var for service code
  char serviceyn = 'n';                            //Define var for user verify
  int i = 1;                                       //Define var for sentinel loop

  do {
    cout << "\n" << "Please enter your service code, [R]egular or [P]remium:" << "\n";
    cin >> servcode;
    while ((servcode != 'R' && servcode != 'P' && servcode != 'r' && servcode != 'p' ) && (i < 3))
      {
    cout << "\n" << "Error - invalid service code, please try again. ";
    cout << "\n" << "Please enter your service code: ";
    cin >> servcode;
    i++;
    if (i == 3)
      {
        cout << "\n" << "Too many invalid attempts, program terminating." << "\n"
         << "Have a nice day. " << "\n" << "\n";
        exit (0);
      }     //end if
      }     //end while
    cout << "\n" << "You entered: " << servcode << "\n"
     << "Is that correct? [y,n]";
    cin >> serviceyn;
      } while (serviceyn != 'y'); // end do/while loop

  return servcode;
}

/************************************************/
/* Name: regserv                                */
/* Description: Calculations for regular serv   */
/* Parameters: N/A                              */
/* Return Value: regserv                        */
/************************************************/

float regserv ()
{
  int regmin = 0;     //Var for number of minutes used
  float regserv = 0;  //Var for cost for regular service


  cout << "\n" "Please enter the minutes used: " << "\n";
  cin >> regmin;
  regserv = (regmin - 50) * 0.2 + 10;

  return regserv;

}

/************************************************/
/* Name: premserv                               */
/* Description: Calculations for premium serv   */
/* Parameters: N/A                              */
/* Return Value: premserv                       */
/************************************************/

float premserv (int& daymin, int& nightmin)
{
   float daytotal = 0;     //Var for day total
  float nighttotal = 0;   //Var for night total
  float premserv = 0;     //Var for premium service cost

  cout << "\n" << "Please enter the number of minutes used durring the day (6AM - 6PM): " << "\n";
  cin >> daymin;
  cout << "\n" << "Please enter the number of minutes used durring the night (6PM - 6AM): " << "\n";
  cin >> nightmin;

  daytotal = (daymin - 75) * 0.1;
  nighttotal = (nightmin - 100) * 0.05;
  premserv = 25 + daytotal + nighttotal;

  return premserv;

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T06:50:02+00:00Added an answer on May 26, 2026 at 6:50 am

    You call regserv() or premserv() inside the switch statement, but then you unconditionally call them both immediately after the switch.

    The comment on the switch suggests that you’ve misunderstood the semantics of switch. It doesn’t “select” what’s to going to happen next, it actually runs the code inside the switch, so you don’t need to invoke them after the switch. However, don’t forget to assign the premiumserv and regularserv variables and perform output inside the switch statement, e.g.:

    ...
    case 'R':
        regularserv = regserv();
        cout << ... regularserv ...
        break;
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to design a c# program which can run program a 3rd exe
To run a program with custom env settings, we do this on Linux $
How should I run another program from within my C program? I need to
When I run the program from IDE (VS2008) it works perfectly. When I want
When you run a program through the command line, you can use java -Xms
Whenever I run my program, I get: NullReferenceException was unhandled, Object Reference not set
Typically when you run any program, during execution time what are different storages available
I am trying run a program from a qmake .pro file which modifies the
When I run my program core.py ( http://pastebin.com/kbzbBUYd ) it returns: File core.py, line
When I first run my program and type some text in the richtextbox, if

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.