Comparing age of two friends of different age – CSKC
Sign In

Search

Code Learning #CPP#1880    siteicon   siteicon  

Comparing age of two friends of different age

With this program we can find who is elder amongst the friends of different age.

Learning Objectives

  • Seeing an if-else condition handle different items only. Handling equality is not there.

Source Code

TC++ #1880

 

Source Code

×

Ask AI About This Code

Default Prompt that is passed along with the code is given below, You can write your own prompt if you so desire.



×

Test CPP

  Related ( ? ) :

Code Understanding

int sa,fa; cout<<“Enter your age : “;cin>>sa; cout<<“Enter your friend’s age : “;cin>>fa;
Two ages are being collected here.

if(sa>fa) cout<<“You are older than your friend.”<<endl;
This is when you are older.

else cout<<“You friend is older than you.”<<endl;
This is when your friend is older.

 

Notes

 

Common Errors

  • Since this is not a type of if-else ladder, so multiple else if conditions are not checked here and hence the case of same age of two friends will not give correct output.


Suggested Filename(s): agecomparison.cpp, unequalage.cpp



Share

Created: 23-Dec-2017 13:38 | Updated: 15-Sep-2018 11:32|