In: Computer Science
Using C++, Right down a code that calculates insurance price:
* requires driver to enter their age and the amounts of accidents they have had
based on that:
*base price is $500
*additional fees of $100 if driver is younger than 25
*additional fees based on accidents:
number of accidents | fees of accidents |
1 | 50 |
2 | 125 |
3 | 225 |
4 | 375 |
5 | 575 |
6 or more | no insurance |
*Use switch
*if had 6 or more accidents won't be able to get insurance
Using C++,calculates insurance price:
Program:
#include
using namespace std;
int main(){
int base = 500;
int age;
int number_of_accidents;
int choice;
cout << "
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
";
cout << " * Calculating insurance price: *
";
cout << "
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
";
do{
cout << " 1.Calculate the
insurance ";
cout << "2.Exit the program
";
cout << "Enter you choice
:";
cin >> choice;
switch(choice){
case 1:
cout << " Enter the age: ";
cin >> age;
if(age < 25){
base += 100;
}
cout << "Number of accidents: ";
cin >> number_of_accidents;
switch(number_of_accidents){
case 1:
base +=
50;
cout
<< "Insurance price is " << base << " ";
break;
case 2:
base +=
125;
cout
<< "Insurance price is " << base << " ";
break;
case 3:
base +=
225;
cout
<< "Insurance price is " << base << " ";
break;
case 4:
base +=
375;
cout
<< "Insurance price is " << base << " ";
break;
case 5:
base +=
575;
cout
<< "Insurance price is " << base << " ";
break;
case 6:
cout
<< "no insurance for 6 or more accidents ";
break;
default :
cout
<< "no insurance for 6 or more accidents ";
break;
}
}
}while(choice != 0);
return 0 ;
}