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.
|