CHALLENGE ACTIVITY 3.3.2: If-else statements. Write multiple if statements: If carYear is before 1968, print "Probably has few safety features." (without quotes). If after 1970, print "Probably has head rests.". If after 1992, print "Probably has anti-lock brakes.". If after 2000, print "Probably has airbags.". End each phrase with period and newline. Ex: carYear = 1995 prints:

Answer :

ammary456

Answer:

#include <iostream>

using namespace std;

int main() {

   int carYear;

   carYear = 1995;

   if(carYear < 1968)

       cout << "Probably has few safety features." << endl;

 

   if(carYear > 1970)

        cout << "Probably has head rests." << endl;

   if(carYear > 1992)

       cout << "Probably has anti-lock brakes." << endl;

   if(carYear > 2000)

       cout << "Probably has airbags." << endl;

   return 0;

}

Explanation:

  • Declare the carYear variable with int as data type.
  • Initialize carYear with any value like 1995.
  • Add an If statement for each case and then print the corresponding message.

Output:

Probably has anti-lock brakes.

Probably has airbags.

Other Questions