Stuck but really really close.

Hi everyone. I tried posting this yesterday but I copied and pasted the wrong thing. First off I am sorry that this code is no where near beautiful. I am a new cs student who is just trying to survive intro comp sci and comp sci 2. My question is how can i get the account number the user has entered appear first in the output?

For example I would like the program to output:
The Account Number.
The Service Type. (Premium or Regular)
The total number of minutes used.
and the amount of money due.

So far it does everything with the exception of outputting the Account Number. If someone could show me what I am doing wrong I would appreciate it.

Thanks. :)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
 #include <iostream>
#include <iomanip>
#include <string>
using namespace std;

void regular() //function to calculate the regular service charge.
{
  int min;
  float startReg = 10.00;
  cout<<"Enter Minutes Used." << endl;
  cin>> min;
  if(min < 50)
    {
      cout<<left;
      cout<< setw(30)<< "Service: " << "Regular" << endl;
      cout<< setw(30)<< "Number of minutes used: " << min << endl;
      cout<< setprecision(2) << fixed;
      cout<< setw(30)<< "Amount Due: " << startReg << endl;
    }
  else
    {
      cout<<left;
      cout<< setw(30)<< "Service: " << "Regular" << endl;
      cout<< setw(30)<< "Number of minutes used: " << min << endl;
      cout<< setprecision(2) << fixed;
      startReg = 10.00 + (min * 0.20);
      cout<< setw(30)<<"Amount Due: " << "$" << startReg << endl;
    }
}
void premium() //function to calculate the premium service charge.
{
  int minDay;
  int minNight;
  float startRegPre = 25.00;
  float endRegPrice;
  float endRegPriceN;

  cout<<"Enter minutes used between 6:00 AM and 6:00 PM" << endl;
  cin>> minDay;

  cout<<"Enter minutes used between 6:00 PM and 6:00 AM" << endl;
  cin>>minNight;
  if(minDay < 75) // premium day minutes.
    {
      cout<< left;
      cout<< setw(30) << "Service: " << "Premium" << endl;
      cout<< setw(30) << "Number of minutes used: " << minNight + minDay << endl;
      cout<< setprecision(2) << fixed;
cout<< setw(30) << "Amount Due: " << "$" << startRegPre << endl;
      return;
    }
  else if(minDay > 75)
    {
      cout<<left;
      cout<< setw(30) << "Service: " << "Premium" << endl;
      cout<<setw(30) << "Number of minutes used: " << minNight + minDay<< endl;
      cout<< setprecision(2) << fixed;
      endRegPrice = (minDay - 75) * 0.10;
      cout<<setw(30)<<"Amount Due: " << "$" << endRegPrice + startRegPre << endl;
      return;
    }

  else if (minNight < 100) //premium night minutes.
    {
      cout<< left;
      cout<< setw(30)<< "Number of minutes used: " << minNight + minDay << endl;
      cout<< setprecision(2) << fixed;
      return;
    }
  else if (minNight > 100);
  {
    cout<< left;
    cout<< setw(30)<< "Number of minutes used: " << minNight + minDay << endl;
    cout<< setprecision(2) << fixed;
    endRegPriceN = (minNight - 100) * 0.05;
    cout<< setw(30) << "Amount Due: " << "$" <<(endRegPriceN + startRegPre) << endl;
    return;
  }
}

int main() //main function.  Takes the service code and account number.
{
  char service;
  string account;
  cout<<"Welcome to the phone bill calculator!" << endl;
  cout<<"-------------------------------------" << endl;
  cout<<"Enter Account Number" << endl;
  cin>> account;
  cout<<"Enter service code" << endl;
  cin>> service;
  switch (service) // switch statement using the service code as a expression.
    {
    case 'r':
    case 'R':
      regular(); // calling the regular service function defined in the start of the program.
      break;

    case 'p':
    case 'P':
      premium(); //calling the premium service function defined in the start of the program.
      break;

    default: // default statement
      cout<<"Enter valid code" << endl;
    }
}

Just pass the account number to the regular() and premium() functions as an argument.

By the way, I think you might need to look at your logic in the premium() function. The third and fourth blocks of code are only entered if minDay == 75. Is that what you want? And if minDay == 75 and minNight == 100, none of the blocks of code are exercised. Is that what you want?
And if minDay == 75 and minNight == 100, none of the blocks of code are exercised.

That's not entirely true. See the semi-colon on line 70. Lines 71 through 77 are not governed by an if or if/else statement.
Good catch, @cire. I've been bitten by that subtlety before in my own code, and I still missed it here.
Thanks Guys :)
Topic archived. No new replies allowed.