a)Write an if-else statement with multiple branches. If givenYear is 2100 or greater, print "Distant future" (without quotes). Else, if givenYear is 2000 or greater (2000-2099), print "21st century". Else, if givenYear is 1900 or greater (1900-1999), print "20th century". Else (1899 or earlier), print "Long ago". Do NOT end with newline #include <iostream> int main() { carYear = 1940; /* Your solution goes here */ return 0; |
#include <iostream>
using namespace std;
int main() {
int givenYear = 0;
//givenYear = 1776;
cout<<"Enter givenYear:";// prompting user to enter input
givenYear
cin>>givenYear;// taking input from console
if(givenYear>=2100){// if given year greaterthan 2100
cout<<"Distant future"<<endl;// print message
}else if(givenYear>=2000 &&givenYear<=2099){// else
if condition checks i.e year between 2000 to 2099
cout<<"21st century"<<endl;// as follows
}
else if(givenYear>=1900 &&givenYear<=1999){
cout<<"20th century"<<endl;
}else if(givenYear>=0 &&givenYear<=1899){
cout<<"Long ago"<<endl;
}
return 0;
}
Get Answers For Free
Most questions answered within 1 hours.