M
Morgan
I am new to Programming and need a little help.
I am trying to figure out how to validate information! I have the loop
writen but, when you enter a none integer number into the a varible
defined as an int the program does not finsh! Can any one please
help???? Here is my code:
# include <iostream>
# include <iomanip>
using namespace std;
int main()
{
double hours;
char choice;
char x = '"';
cout << "Please Select what Type of Subscription the Customer has? "
<< endl;
cout << "A: Package (A) = $9.95 per month for 10 hours and $2.00 per
hour over 10. " << endl;
cout << "B: Package (B) = $14.95 per month for 20 hours and $1.00 per
hour over 20. " << endl;
cout << "C: Package (C) = $19.95 per month for unlimited access. " <<
endl;
cout << "Please make a selection: ";
cin >> choice;
system ( "cls");
while ( choice != 'a' && choice != 'A' && choice != 'b' && choice !=
'B' && choice != 'c' && choice != 'C')
{
cout << x << choice << x << " is not a Valid Selcection " <<
endl ;
cout << "Please Try Again! " << endl;
cout << "Please Select what Type of Subscription the Customer has?
" << endl ;
cout << "A: Package (A) = $9.95 per month for 10 hours and $2.00
per hour over 10. " << endl;
cout << "B: Package (B) = $14.95 per month for 20 hours and $1.00
per hour over 20. " << endl;
cout << "C: Package (C) = $19.95 per month for unlimited access. "
<< endl;
cout << "Please make a selection: ";
cin >> choice;
system ( "cls");
}
switch (choice)
{
double monthly;
double hours2;
case 'a':
case 'A': cout << " How many hours did the customer use?:";
cin >> hours;
system ( "cls");
while (hours < 0 || hours < 744)
{
cout << x << hours << x << " is an invalid amount! " << endl;
cout << "Amount cannot be negative, or over 744 hours. " << endl;
cout << "Please re-enter correct amount. " << endl;
cout << "How many hours did the customer use?:";
cin >> hours;
system ( "cls");
}
if (hours <= 10)
{
cout << "The Customer should be billed: $" << "9.95" << endl;
}
else if (hours > 10)
{
hours2 = hours - 10 ;
monthly = 9.95 + (hours2 * 2.00);
cout << "The Customer should be billed: $" << monthly << endl;
}
break;
case 'b':
case 'B': cout << " How many hours did the customer use?";
cin >> hours;
system ( "cls");
while (hours < 0 || hours > 744)
{
cout << x << hours << x << " is an invalid amount! " << endl;
cout << "Amount must be a number, and cannot be negative, or over
744 hours. " << endl;
cout << "Please re-enter correct amount. " << endl;
cout << "How many hours did the customer use?:";
cin >> hours;
system ( "cls");
}
if (hours <= 20)
{
cout << "The Customer should be billed: $14.95" << endl;
}
else if (hours > 20)
{
hours2 = hours - 20 ;
monthly = 14.95 + (hours2 * 1.00);
cout << "The Customer should be billed: $" << monthly << endl;
}
break;
case 'c':
case 'C': cout << "The Customer should be billed: $19.95 " << endl;
break;
default: cout << "That is an Invalid Selection! " << endl;
cout << "Please select again! " << endl;
}
cin.ignore();
cout << "Press Enter to Close";
cin.get();
return 0;
}
I am trying to figure out how to validate information! I have the loop
writen but, when you enter a none integer number into the a varible
defined as an int the program does not finsh! Can any one please
help???? Here is my code:
# include <iostream>
# include <iomanip>
using namespace std;
int main()
{
double hours;
char choice;
char x = '"';
cout << "Please Select what Type of Subscription the Customer has? "
<< endl;
cout << "A: Package (A) = $9.95 per month for 10 hours and $2.00 per
hour over 10. " << endl;
cout << "B: Package (B) = $14.95 per month for 20 hours and $1.00 per
hour over 20. " << endl;
cout << "C: Package (C) = $19.95 per month for unlimited access. " <<
endl;
cout << "Please make a selection: ";
cin >> choice;
system ( "cls");
while ( choice != 'a' && choice != 'A' && choice != 'b' && choice !=
'B' && choice != 'c' && choice != 'C')
{
cout << x << choice << x << " is not a Valid Selcection " <<
endl ;
cout << "Please Try Again! " << endl;
cout << "Please Select what Type of Subscription the Customer has?
" << endl ;
cout << "A: Package (A) = $9.95 per month for 10 hours and $2.00
per hour over 10. " << endl;
cout << "B: Package (B) = $14.95 per month for 20 hours and $1.00
per hour over 20. " << endl;
cout << "C: Package (C) = $19.95 per month for unlimited access. "
<< endl;
cout << "Please make a selection: ";
cin >> choice;
system ( "cls");
}
switch (choice)
{
double monthly;
double hours2;
case 'a':
case 'A': cout << " How many hours did the customer use?:";
cin >> hours;
system ( "cls");
while (hours < 0 || hours < 744)
{
cout << x << hours << x << " is an invalid amount! " << endl;
cout << "Amount cannot be negative, or over 744 hours. " << endl;
cout << "Please re-enter correct amount. " << endl;
cout << "How many hours did the customer use?:";
cin >> hours;
system ( "cls");
}
if (hours <= 10)
{
cout << "The Customer should be billed: $" << "9.95" << endl;
}
else if (hours > 10)
{
hours2 = hours - 10 ;
monthly = 9.95 + (hours2 * 2.00);
cout << "The Customer should be billed: $" << monthly << endl;
}
break;
case 'b':
case 'B': cout << " How many hours did the customer use?";
cin >> hours;
system ( "cls");
while (hours < 0 || hours > 744)
{
cout << x << hours << x << " is an invalid amount! " << endl;
cout << "Amount must be a number, and cannot be negative, or over
744 hours. " << endl;
cout << "Please re-enter correct amount. " << endl;
cout << "How many hours did the customer use?:";
cin >> hours;
system ( "cls");
}
if (hours <= 20)
{
cout << "The Customer should be billed: $14.95" << endl;
}
else if (hours > 20)
{
hours2 = hours - 20 ;
monthly = 14.95 + (hours2 * 1.00);
cout << "The Customer should be billed: $" << monthly << endl;
}
break;
case 'c':
case 'C': cout << "The Customer should be billed: $19.95 " << endl;
break;
default: cout << "That is an Invalid Selection! " << endl;
cout << "Please select again! " << endl;
}
cin.ignore();
cout << "Press Enter to Close";
cin.get();
return 0;
}