Write a C program Write a program that asks the user to ente

Write a C++ program

Write a program that asks the user to enter his/her: First name Middle name last name and year of birth(one at a time), If the user doesn\'t have a middle name, he/she is asked to enter N/A. The program calculates the age of the user and then shows the full name and the age of the user and also determines if the user has reached the age of majority in Canadian provinces. The age of majority is 18 in six provinces: Alberta, Manitoba, Ontario, Prince Edward Island, Quebec, and Saskatchewan. The age of majority is 19 in four provinces and the three territories: British Columbia, New Brunswick, Newfoundland, Northwest Territories, Nova Scotia, Nunavut, and Yukon.

Solution

#include <iostream>
using namespace std;

int main() {
   // your code goes here
   string first_name,middle_name,last_name;
   int year;
  
   cout << \"Enter your first name : \";
   cin >> first_name;
  
   cout << \"Enter your middle name(If not applicable enter N/A) : \";
   cin >> middle_name;
  
   cout << \"Enter your last name : \";
   cin >> last_name;
  
   cout << \"Enter year of your birth : \";
   cin >> year;
  
   int age = 2016-year;
   bool majority = age>=18?true:false;
   string middle_p = middle_name==\"N/A\"?\"\":middle_name;
  
   cout << \"Name of user is : \" << first_name << \" \" << middle_p << \" \" << last_name << \" age is : \" << age << \" and reached majority : \" << majority << endl;
   return 0;
}

Write a C++ program Write a program that asks the user to enter his/her: First name Middle name last name and year of birth(one at a time), If the user doesn\'t

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site