# Help looking over

• October 13th, 2012, 12:57 PM
cwarden12
Help looking over
A friend asked me to get someone to look over this but the guy is offline, so I'm asking around here... here's his project:

Project for my intro to programming class, someone wanna read over it and see if they're are any glaring holes?
Code:

```//Travis C    Page 226 Problem 23 Internet Provider //October 9th, 2012 // // /* DESIGN BLOCK */ #include <iostream> using namespace std; int main () { int choice; int hours; double total; double A = 9.95; double B = 14.95; double C = 19.95; double D = 2.00; double E = 1.00; cout << " Travis' Internet Service Provider Subscription\n"; cout << "1. \$9.95 per month. 10 hours access. Additional Hours are \$2.00\n"; cout << "2. \$14.95 per month. 20 hours access. Additional hours are \$1.00\n"; cout << "3. \$19.95 per month. Unlimited access.\n"; cout << "Please enter the subscription number of your choice: "; cin >> choice; if (choice >=1 && choice <=3) { cout << "How many hours would you access: "; cin >> hours;   switch (choice) { case 1: { total = A + (hours - 10)*D; break; } case 2: { total = B + (hours - 20)*E; break; } case 3: { total = C; break; } default: cout<<"You entered a wrong value!"<<endl; cout << "The valid choices are 1 through 3. \n Run the program again."; } cout << "The total for your subcription is:\$ "<<total<<endl; }   else if (choice !=3) { cout << "The valid choices are 1 through 3. \n Run the program again."; } return 0; } /* Output  Travis' Internet Service Provider Subscription 1. \$9.95 per month. 10 hours access. Additional Hours are \$2.00 2. \$14.95 per month. 20 hours access. Additional hours are \$1.00 3. \$19.95 per month. Unlimited access. Enter your choice: 1 How many hours would you access: 12 The total for your subscription is:\$ 13.95 Press any key to continue . . . */```
• October 13th, 2012, 01:13 PM
Peter_B
Re: Help looking over
Quote:

Originally Posted by cwarden12
Project for my intro to programming class, someone wanna read over it and see if they're are any glaring holes?
Code:

```... int main () { ... double A = 9.95; ... double D = 2.00; ... cout << " Travis' Internet Service Provider Subscription\n"; cout << "1. \$9.95 per month. 10 hours access. Additional Hours are \$2.00\n"; cout << "Please enter the subscription number of your choice: "; cin >> choice; ... cout << "How many hours would you access: "; cin >> hours; ... switch (choice) { case 1: { total = A + (hours - 10)*D; break; } ...```

(Irrelevant code deleted)

What happens if you choose option 1) and only have 1 hour usage? :)
• October 13th, 2012, 01:15 PM
laserlight
Re: Help looking over
One thing that you need to do is to format your code, e.g., to indent it.
• October 13th, 2012, 02:40 PM
GCDEF
Re: Help looking over
As Peter pointed out, your calculations don't work.

You don't really need the default in the switch statement as you're already weeding out invalid choices in the if statement.

Typically, you'll verify input in a while loop, repeating until valid data is entered, rather than exiting the program and asking the user to rerun it.

Next time, please use code tags.