Question

Write a c++ program that asks the user for his birth year. If the birth year...

Write a c++ program that asks the user for his birth year. If the birth year is later than 2000, then the program outputs the string “You were born in the 21st century”. If the birth year is not greater than 2000, then the program enters the else clause of the outer if statement. This clause starts by outputting the string “You were born in” before comparing the birth year to 1950. If the birth year is less than 1950, then the program adds the first “the first half”. If the birth year is not less than 1950, then the else clause of the inner if statement is executed, which tacks on the phrase “the second half”. Finally, the program adds the concluding phrase “of the 20th century” to whatever has been output so far.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code:

#include <iostream>

using namespace std;

int main()
{ //to store the birth year
int birth_year;
  
//input of birth year
cout<<"Enter Your Birth Year: ";
cin>>birth_year;
  
//if birth year is in 21 century
if(birth_year>=2000){
cout<<"You were born in the 21st century.";
}
  
//if birth year is not in 21 century
else{
cout<<"You were born in ";
  
//if birth_year is less than 1950
if(birth_year<1950){
cout<<"the first half";
}
// if birth_year is more than 1950
else{
cout<<"the second half";
}
cout<<" of the 20th century.";
}
return 0;
}
OUTPUT:

Add a comment
Know the answer?
Add Answer to:
Write a c++ program that asks the user for his birth year. If the birth year...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • in python Write a program that reads the date of birth from the user as 3...

    in python Write a program that reads the date of birth from the user as 3 integer values (day, month, year) and then computes and prints their exact age in days. You need to take into account the leap You may not use any built-in functions related to date and time! Example: Someone born on 01/01/2000 is 365 days * 18 years + 5 days (since the years 2000, 2004, 2008, 2012, and 2016 are all leap years) + 352...

  • Write an if-else statement that checks patronAge. If 55 or greater print 'Senior citizen', otherwise print...

    Write an if-else statement that checks patronAge. If 55 or greater print 'Senior citizen', otherwise print 'Not senior citizen' (without quotes). End with newline. 1 import java.util.Scanner; Test pas public class DetectSenior public static void nain (String[] args) { Scanner sehr = new Scanner(System.in); int patronage; patronage - ser.nextInt(); * Your solution goes here */ 12 13 Write an if-else statement with multiple branches. If given Year is 2101 or greater print 'Distant future" (without quotes). Else, if given Year...

  • In C++ write a program that will read three strings from the user, a phrase, a...

    In C++ write a program that will read three strings from the user, a phrase, a letter to replace, and a replacement letter. The program will change the phrase by replacing each occurrence of a letter with a replacement letter. For example, if the phrase is Mississippi and the letter to replace is 's' the new phrase will be "miizzizzippi". in the function, replace the first parameter is a modifiable string, the second parameter is the occurrence of a letter...

  • In a file called First SecondNext.java, write a program that: • Asks the user to enter...

    In a file called First SecondNext.java, write a program that: • Asks the user to enter a string that contains at least five letters. It is OK if your program crashes when the user enters a string with length less than 5. • Stores that string in a variable called s. • Creates a variable called "first", and sets it equal to the first letter of s. • Creates a variable called "second", and sets it equal to the second...

  • Write a program that ask the user for the year he/she was born, then outputs "Hi"...

    Write a program that ask the user for the year he/she was born, then outputs "Hi" if the user is less than 18 years old but "Hello" if the user is 18 or older. The program should print "Bye" at the end. cpp.

  • C++ program Please only (if) (else) statements No while statements use Write a program that takes...

    C++ program Please only (if) (else) statements No while statements use Write a program that takes rate and outputs the employee's wages for the week input employee's hours worked and regular pay as an Calculate employee's wages as follows: She receives her regular rate for the an first 40 hours, 1.5 times her regular rate for each hour between 40 and 50 hours, and double her regular rate for each hour over 50. For invalid inputs, in addition to outputting...

  • Write a function to determine the day of the week a person was born given his...

    Write a function to determine the day of the week a person was born given his or her birthday. The following steps should be used to find the day of the week corresponding to any date from 1901 through the present. In the following explanation, the following terms will be helpful. Assuming I type in my birthday as "6 10 1981": The month is 6. The day of the month is 10. The year is 1981. Find the number of...

  • Write a C++ program that asks for the following information about a book order from the...

    Write a C++ program that asks for the following information about a book order from the console: • Title • Author • ISBN (hint: careful about what data type to use - validate 9 or 13 characters) • Price (validate number < 400) • Quantity (number of books to purchase – validate > 0 and < 100) • Fiction/Non-Fiction (‘N’ or ‘F’ - validate) • Genre (‘R’ romance, ‘D’ drama, ‘M’ mystery – validate) Make use of the following data...

  • Project 1, Program Design 1. Write a C program replace.c that asks the user to enter...

    Project 1, Program Design 1. Write a C program replace.c that asks the user to enter a three-digit integer and then replace each digit by the sum of that digit plus 6 modulus 10. If the integer entered is less than 100 or greater than 999, output an error message and abort the program. A sample input/output: Enter a three-digit number: 928 Output: 584 2. Write a C program convert.c that displays menus for converting length and calculates the result....

  • Write a C# program that prints a calendar for a given year. Call this program calendar....

    Write a C# program that prints a calendar for a given year. Call this program calendar. The program prompts the user for two inputs:       1) The year for which you are generating the calendar.       2) The day of the week that January first is on, you will use the following notation to set the day of the week:             0 Sunday                     1 Monday                   2 Tuesday                   3 Wednesday       4 Thursday                 5 Friday                      6 Saturday Your program should...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT