Assume that the rate for getting your motorcycle registered is based on its model year and cc as shown in the following table. Also, for each difference from current year to model year, an extra RM 1.00 per year will be imposed. Write a C++ program with a nested-if statement to calculate the registration rate given the model year and CC. All inputs to be entered by the user
I am not doing your homework for you. If you're haveing trouble with a nested if statement then have your code up to that point, ask a more specific question about where you are stuck, and bring your code with you(post it). If you need help setting it up, ask about setting it up.
I'm not sure if i should use a switch within the nested if (or if thats possible).
Also not really sure how to input the conditions 201cc to 500cc and others like that
if (year <= 2007 && cc>=201 && cc <=500 )
{
cout << "RM 30.00 + (RM 1.00 x diff in year from 2017)" << endl;
}
else
{
if (year <=2007 && cc>=50 && cc <= 800)
{
cout << "RM 50.00 + (RM 1.00 x diff in year from 2017)" << endl;
}
else
{
if (year <=2007 && cc>800)
{
cout <<"RM 120.00 + (RM 1.00 x diff in year from 2017)" << endl;
}
else
{
if (year >=2008 && cc>=201 && cc <=500)
{
cout << "RM 180.00 + (RM 1.00 x diff in year from 2017)" << endl;
}
else
{ if (year >=2008 && cc>=50 && cc <= 800 )
{
cout <<"RM 250.00 + (RM 1.00 x diff in year from 2017)" << endl;
}
else
{
cout << "RM 350.00 + (RM 1.00 x diff in year from 2017)" << endl;
}
}
}
}
}
return 0;
}
A switch inside a if is possible but not necessary. I would have the user input the year of the motorcycle and the CCs. Then use a simple if-else statement, if the motorcycle is from 2007 or before and then just an else statement because if it's not from before then it has to be from after. Next, inside your if statements you will use multiple if and if else statements to test the CCs of the motorcycle and then in each of if statements you will have the formula for that CC motorcycle.
General outline:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
//input year
//input CC
if (year <= 2007)
{
if (CC >= 251 && CC <= 500)
{
//formula
}
elseif ()
{
}
}
else
{
}