Hi there! -- Could use a bit of help?

I've recently enrolled in an introduction to C++ class and could use to help with several problems. I've already tried googling, which helped to a degree, but there are some more minor issues with my source code that I can't seem to figure out.

Problem #1 [ The Question asked]
" Roman Numeral Converter

Write a program that asks the user to enter a number within the range of 1 through 10. Use a switch statement (refer to Chapter 4.12 pgs 210-217) to display the Roman numeral versions of that number.

Input Validation: Do not accept a number less than 1 or greater than 10.

Sample screen output 1 using Code:Blocks:


Enter a number (1 - 10): 12
Enter a number in the range 1 through 10.

Process returned 0 (0x0) execution time : 14.440 s
Press any key to continue.
Sample screen output 2 using Code:Blocks:


Enter a number (1 - 10): 7
The Roman numeral version of 7 is VII.

Process returned 0 (0x0) execution time : 4.838 s
Press any key to continue. "


What I have :
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
#include <iostream>
using namespace std;


int main()
{
    int number;
    cout << "Enter a number from 1 to 10" << endl;
    number <=1, >=10;
    cin >> number;
    switch(number) {
    case 1:
    cout = "i";
    break;
    case 2:
    cout = "ii";
    break;
    case 3:
    cout = "iii";
    break;
    case 4:
    cout = "iv"
    break;
    case 5:
    cout = v;
    case 6:
    cout = "vi";
    break;
    case 7:
    cout = "vii";
    break;
    case 8:
    cout = "viii";
    break;
    case 9:
    cout = "ix";
    break;
    case 10:
    cout = "x";
    default;
    cout = "out of range"

    cout << "The roman numeral for " << number >> " is " << out >> endl;

    return 0;
}

I get errors and it won't run. I've tried modifying the values in various ways, but still can't figure it out.

Problem #2 [Question Asked]
Internet Service Provider

An Internet service provider has three different subscription packages for its customers:

Package A: For $9.95 per month 10 hours of access are provided. Additional are $2.00 per hour.

Package B: For $14.95 per month 20 hours of access are provided. Additional are $1.00 per hour.

Package C: For $19.95 per month unlimited access is provided.

Write a program that calculates a customer's monthly bill. Use a switch statement (refer to Chapter 4.12 pgs 210-217) to display a menu of subscription packages to choose from. It should ask which package the customer has purchased and how many hours were used. It should then display the total amount due.

Input Validation: Be sure the user only selects package A, B, or C. Also, the number of hours used in a month cannot exceed 744.

Sample screen output 1 using Code:Blocks:


Select a subscription package:
1. Package A
2. Package B
3. Package C
4. Quit

b
The valid choices are 1 through 4. Run the
program again and select one of those.

Process returned 0 (0x0) execution time : 4.364 s
Press any key to continue.

Sample screen output 2 using Code::Blocks:

Select a subscription package:
1. Package A
2. Package B
3. Package C
4. Quit

3
How many hours were used? 760
The hours used must be between 0.00 and 744.00.

Process returned 0 (0x0) execution time : 36.039 s
Press any key to continue.
Sample screen output 3 using Code::Blocks:

Select a subscription package:
1. Package A
2. Package B
3. Package C
4. Quit

2
How many hours were used? 450
The total amount due is $444.95

Process returned 0 (0x0) execution time : 18.357 s
Press any key to continue.

Turn in your source code followed by 3 program test outputs, reflecting each of the three sample screen outputs given above.

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
109
110
111
112
113
114
115
116
117
#include <iostream>
#include <string>

using namespace std;
//prototypes
double total(int type, int hours);

int main()
{

    cout << "Which package did you purchase?: A, B, or C?\n\n"
    "A - $9.95 per month with 10 hours allowed. More hours are $2.00 per hour.\n"
    "B - $14.95 per month with 20 hours allowed. More hours are $1.00 per hour.\n"
    "C - $19.95 per month with infinite hours allowed.\n\n";
    char package;
    cin >> package;
    while (package != 'A' && package != 'a' && package != 'B' && package != 'b' && package != 'C' && package != 'c')
    {
    cout << "Invalid selection. Please only enter the letter A, B or C.";
    cout << "Enter your package type A, B or C: ";
    cin >> package;
}
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    switch (package)
    {
           //Package A: For $9.95 per month 10 hours of access are provided. Additional hours
//are $2.00 per hour.
    case 'A':
    case 'a':
         int packagetype;
         packagetype = 1;
         cout << "\nyou picked A.\n\nHow many hours were you on the internet?:\n\n";
    int nethours;
    cin >> nethours;

     while (nethours > 744)
     {
     cout << "\nThat is impossible.";
     cout << "How many hours were you on the internet?:\n\n";
     cin >> nethours;
     }
    break;
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    //Package B: For $14.95 per month 20 hours of access are provided. Additional
//hours are $1.00 per hour.
    case 'B':
    case 'b': cout << "\nYou picked B.\n\nHow many hours were you on the internet?:\n\n";

    cin >> nethours;
    {
   if (nethours <= 20)
{
    cout << "Your bill is 14.95.";
}
    else if (nethours > 20)
    {
         while (nethours > 744)
         {
         cout << "That is impossible. Re-enter your hours.:";
         cin >> nethours;
         }
         //need calculation
          }
          break;
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//Package C: For $19.95 per month unlimited access is provided.
    case 'C':
    case 'c': cout << "\nYou picked C.\nHow many hours were you using internet?:\n";

    cin >> nethours;
    //
     while (nethours > 744)
    {
          cout << "That is impossible. Please re-enter your internet hours.\n";
    cin >> nethours;
}
    //
    if (nethours <= 744)
    {
    cout << "Your bill is $19.95.\n";
}

    break;
    default: cout << "Not a valid answer.\n";
    }
    total(packagetype, nethours);
cin.get ();
return 0;
}
}
//price calculator~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
double total(int type, int hours)
{
      if (type == 1)
      {
               if (hours <= 10)
    {

      cout << "\nyou have a bill of 9.95 in your account because you did not go over the limit.\n";
    }
else if (hours > 10)
  {
        cout << "\nYou have a bill of " << (hours - 10.00) * 1.00 + 9.95  << " in your account because of extra fees.\n\nYou could have saved "
     << ((hours - 20) * 2.00 + 14.95) - ((hours - 10.00) * 1.00 + 9.95) << " dollars if you had package B.\n";
     }
else
{
     cout << "invalid answer to A";
     }
cout << "Press enter to continue.";
cin.get();
cin.get();

}
return 0;
}

That's what I have, however when I run it, I get :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Which package did you purchase?: A, B, or C?

A - $9.95 per month with 10 hours allowed. More hours are $2.00 per hour.
B - $14.95 per month with 20 hours allowed. More hours are $1.00 per hour.
C - $19.95 per month with infinite hours allowed.

b

You picked B.

How many hours were you on the internet?:

450

Process returned 0 (0x0)   execution time : 2.624 s
Press any key to continue.

-- It simply stops there and doesn't give me the total amount due. It should look like :
1
2
3
4
5
6
7
8
9
10
11
12
Select a subscription package:
1. Package A
2. Package B
3. Package C
4. Quit

2
How many hours were used? 450
The total amount due is $444.95

Process returned 0 (0x0) execution time : 18.357 s
Press any key to continue.
With the first problem, I just now noticed line 25's mistake and fixed that so its :
cout = "v";

Still have the problem though.
you have got a lot of error in the first question. why dont you use the << (insertion operator)to indicate what to ouput instead of =. cout << results in a function call with text as an argument to the function.. instead of using =
Last edited on
Problem 1:
You cannot set cout equal to something.
cout only uses '<<' not '>>'.

Problem 2:
This code is a bit of a mess. Try simplifying it. I think the error may be due to you initializing packagetype within case A, but not B or C.

ps: you never use strings, so there's no need to #include <string>
and also In problem 2 to youve got problem in calculations why dont use const to create constant int or double for your calculation in the function total()
Last edited on
Adjusted problem #1 to look like
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
#include <iostream>
using namespace std;


int main()
{
    int number;
    cout << "Enter a number from 1 to 10" << endl;
    number >=1, <=10;
    cin >> number;
    switch(number) {
    case 1:
    cout << "i";
    break;
    case 2:
    cout << "ii";
    break;
    case 3:
    cout << "iii";
    break;
    case 4:
    cout << "iv";
    break;
    case 5:
    cout << "v";
    case 6:
    cout << "vi";
    break;
    case 7:
    cout << "vii";
    break;
    case 8:
    cout << "viii";
    break;
    case 9:
    cout << "ix";
    break;
    case 10:
    cout << "x";
    default;
    cout << "out of range"

    cout << "The roman numeral for " << number >> " is " << cout >> endl;

    return 0;
}





Still getting some sort of problem with line 9 though.
number >=1, <=10;
Just remove the line 9
and chage the ; of line 40 with :
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
#include <iostream>
using namespace std;


int main()
{
    int number;
    cout << "Enter a number from 1 to 10" << endl;
    cin >> number;
    switch(number) {
    case 1:
    cout << "i";
    break;
    case 2:
    cout << "ii";
    break;
    case 3:
    cout << "iii";
    break;
    case 4:
    cout << "iv";
    break;
    case 5:
    cout << "v";
    case 6:
    cout << "vi";
    break;
    case 7:
    cout << "vii";
    break;
    case 8:
    cout << "viii";
    break;
    case 9:
    cout << "ix";
    break;
    case 10:
    cout << "x";
    default:
    cout << "out of range";

    cout << "The roman numeral for " << number >> " is " << cout >> endl;

    return 0;
}



Done, getting an error with the second to last line now.
cout << "The roman numeral for " << number >> " is " << cout >> endl;
cout only uses '<<' not '>>'.

Your arrows are backwards. Change it to:
cout << "The roman numeral for " << number << " is " << cout << endl;
Last edited on
Fixed.
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
#include <iostream>
using namespace std;


int main()
{
    int number;
    cout << "Enter a number from 1 to 10" << endl;
    cin >> number;
    switch(number){
    case 1:
    cout << "The Roman numeral of 1 is I/n";
    break;
    case 2:
    cout << "The Roman numeral of 2 is II/n";
    break;
    case 3:
    cout << "The Roman numeral of 3 is III/n";
    break;
    case 4:
    cout << "The Roman numeral of 4 is IV/n";
    break;
    case 5:
    cout << "The Roman numeral of 5 is V/n";
    break;
    case 6:
    cout << "The Roman numeral of 6 is VI/n";
    break;
    case 7:
    cout << "The Roman numeral of 7 is VII";
    break;
    case 8:
    cout << "The Roman numeral of 8 is VIII/n";
    break;
    case 9:
    cout << "The Roman numeral of 9 is IX/n";
    break;
    case 10:
    cout << "The Roman numeral of 10 is X";;
    default:
    cout << "out of range";
    cout << "The roman numeral for " << number << " is " << cout >> endl;

    return 0;
}


Still getting an error in that. I don't know where to put the end brace } for the switch function. Where would it go after? I just have it there without a current end.

No end bracehere :
switch(number){
Would it just be :
switch(number){)
?
That doesn't seem to work either
Last edited on
Just add one end brace in the last line
Edit: Don't do this.

Oh, and move cout << "The roman numeral for " << number << " is "; to before the switch, and just have cout << endl; after the switch.
Last edited on
@Yay295 if the op move it the output will be duplicated
Last edited on
Oops, you're right. I missed that somehow.
Thankyou all for the help. I've figured out Problem #1 and #2, but now have a third if anyone's up to it.

Problem #3 (Question Asked)
The phone company uses the following rate structure for calls from San Francisco to Seattle, Washington:

Any call started at or after 6:00 pm (1800) but before 8:00 am (800) is discounted 50%.

All calls are subject to a 4% federal tax.

The regular rate is $0.35 per minute.

Any call longer than 60 minutes receives a 16% discount on its cost (after any other discount is subtracted but before tax is added).

Write a program that reads from the user the start time for a call based on a 24-hour clock and the length of the call in minutes. The gross cost (before any discount or tax) should be printed, and then the net cost (after discounts and taxes). Turn in 4 outputs for this exercise, showing that your program works in each of the following 4 cases. Use the input examples shown here, don't make up your own.

Sample output 1:


Enter start time: 2322
Enter length of call in minutes: 67
gross cost: $23.45
net cost: $10.24
Sample output 2:


Enter start time: 759
Enter length of call in minutes: 10
gross cost: $3.50
net cost: $1.82
Sample output 3:


Enter start time: 1300
Enter length of call in minutes: 100
gross cost: $35.00
net cost: $30.58
Sample output 4:


Enter start time: 1300
Enter length of call in minutes: 10
gross cost: $3.50
net cost: $3.64


Turn in your source code followed by 4 program test outputs, reflecting each of the four sample screen outputs given above.

What I have:
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
#include <iostream>

    using namespace std;

    int main()
    {
        int StartTime;
        int LengthofCall;
        const float fedTax = .04;
        const float rate = .35;
        const float discount = .05;
        const float discountOnMin = .16;
        float grossCost;
        float PriceofStartTime;
        float PriceofLengthofCall;
        float netCost;





        cout << "Enter start time: "<<endl;
        cin >> StartTime;
        cout << "Enter length of the call in minutes: "<<endl;
        cin >> LengthofCall;


        if (StartTime >=1800 || StartTime<800)
        if (LengthofCall<60)
          { PriceofStartTime =(StartTime*fedTax);
           PriceofLengthofCall=(LengthofCall*rate);
           grossCost=  PriceofStartTime + PriceofLengthofCall;
           cout << "Gross cost: "<<grossCost<<endl;
           netCost= (PriceofStartTime*discount) + PriceofLengthofCall;
           cout << "Net cost: "<< netCost << endl;
           }

        else if (StartTime<1800 || StartTime>800)
             if (LengthofCall>60)
         { PriceofStartTime =(StartTime*fedTax);
           PriceofLengthofCall=(LengthofCall*rate);
           grossCost=  PriceofStartTime + PriceofLengthofCall;
           cout << "Gross cost: "<<grossCost<<endl;
           netCost= PriceofStartTime + (PriceofLengthofCall*discountOnMin);
           cout << "Net cost: "<< netCost << endl;
           }

        else if (StartTime >=1800 || StartTime<800)
             if (LengthofCall>60)
         { PriceofStartTime =(StartTime*fedTax);
           PriceofLengthofCall=(LengthofCall*rate);
           grossCost=  PriceofStartTime + PriceofLengthofCall;
           cout << "Gross cost: "<<grossCost<<endl;
           netCost= (PriceofStartTime*discount)+
                    (PriceofLengthofCall*discountOnMin);
           cout << "Net cost: "<< netCost << endl;
           }


          else if (StartTime<1800 || StartTime>800)
               if (LengthofCall<60)
           { PriceofStartTime =(StartTime*fedTax);
           PriceofLengthofCall=(LengthofCall*rate);
           grossCost=  PriceofStartTime + PriceofLengthofCall;
           cout << "Gross cost: "<<grossCost<<endl;
           netCost=grossCost ;
           cout << "Net cost: "<< netCost << endl;
           }
           return 0;
           }
           


Problem : The program runs fine, though i've tried entering the numbers to match the samples in the question asked and the results are either incorrect, or the program simply stops in the case of 1300 as a start time. Anyone have any idea?
The second two else statements will never be called. The first two handle all possibilities.
The first two and last two differ in the lengths of the calls made. Won't the length of the call decide between which are used?
No, because that if statement is inside the other if statement.
How would I fix that?
Instead of
1
2
if (StartTime >=1800 || StartTime<800)
    if (LengthofCall<60)

use
if ( ( StartTime >= 1800 || StartTime < 800 ) && LengthofCall < 60 )
Topic archived. No new replies allowed.