the program i wrote: it works alright if i input a number, but any mist ake to input a letter, it will cause the program run infinitely. Any comment or help to fix the problem will be very appreciated.
#include <iostream.h>
int main ()
{
double premium, discounted;
int age, accident, units;
do
{
cout << "Enter your age:" ;
cin >> age;
if ( age <= o)
cout << " error input, try again : " ;
} while ( age <= 0 ) ;
cout << "Enter accident if you had in the past, (yes = 1 and no = 0): " ;
cin >> accident ;
cout << "Enter number of units if you are a student ; if not, enter 0: " ;
cin >> units;
if ( age >= 26 && accident > 0 && units >= 12 )
premium = 80 - ( 80*0.05 ), discounted = ( 80*0.05 ) ;
else if ( age >=26 && accident <= 0 && units >= 12 )
premium = 80 - ( 80*0.05 + 80*0.10 ), discounted = ( 80*0.05 + 80*0.10 ) ;
else if ( age >=26 && accident <= 0 && units < 12 )
premium = 80 - ( 80*0.10 ), discounted = ( 80*0.10 ) ;
else if ( age >=26 && accident > 0 && units < 12 )
premium = 80, discounted = 0 ;
else if ( (age < 26 && age >= 18 ) && accident > 0 && units >= 12 )
premium = 100 - ( 100*0.05 ), discounted = ( 100*0.05 ) ;
else if ( ( age < 26 && age >= 18 ) && accident <= 0 && units >= 12 )
premium = 100 - ( 100*0.15 ), discounted = ( 100*0.15 ) ;
else if ( ( age < 26 && age >= 18 ) && accident <= 0 && units < 12 )
premium = 100 - ( 100*0.10 ), discounted = ( 100*0.10 ) ;
else if ( ( age < 26 && age >= 18 ) && accident > 0 && units < 12 )
premium = 100, discounted = 0 ;
else if ( age < 18 && accident > 0 && units >= 12 )
premium = 150 - ( 150*0.05 ), discounted = ( 150*0.05 ) ;
else if ( age < 18 && accident <= 0 && units >= 12 )
premium = 150 - ( 150*0.15 ), discounted = ( 150*0.15 ) ;
else if ( age < 18 && accident <= 0 && units < 12 )
premium = 150 - ( 150*0.10 ), discounted = ( 150*0.10 ) ;
else if ( age < 18 && accident > 0 && units < 12 )
premium = 150, discounted = 0 ;
cout << "discounted :" << discounted << endl;
cout << "premium : " << premium << endl;
return 0;
}