Body temperature diagnosis and diversion – Multiple if and if ladder – CSKC
Sign In

Search

Code Learning #CPP#1950    siteicon   siteicon  

Body temperature diagnosis and diversion – Multiple if and if ladder

Handling of patients diversion to doctors based on there body temperatures using multiple if and if ladder.

Learning Objectives

  • Learning to use multiple if when it may sound more logical based on probability of occurrance of certain data input values.
  • Multiple if followed by a if ladder for other range.
  • Giving typical error messages related to out of if-ladder range of values.

Source Code

TC++ #1950

 

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

Code Understanding

if(body_temp<=98.6 && body_temp>=97) {cout<<“You are okay”<<endl;return 0;}
This portion of code has been separated as it is most common case. May be maximum people visiting a hospital may fall into this category. So it has been separately checked and program returns.

if(body_temp>103 && body_temp<110) cout<<“Go to Emergency Ward”<<endl;
else if(body_temp<=103 && body_temp>100) cout<<“Go to Doctor X”<<endl;
else if(body_temp<=100 && body_temp>98.6) cout<<“Go to Doctor Y”<<endl;
else cout<<“Unable to handle input value”<<endl;
This is typical if ladder for all other cases. The special case of out of lower and maximum range has been given a different message.

Notes

  • The program can be equally efficient using if else construct, but many people find it convenient to handle such code constructs for understanding a program behaviour in most commonly occurring case of data input.

Common Errors

  • Many times programmers commit error related to { } braces in the if blocks.
  • The first if block if written without braces will lead to early termination of program in all conditions.


Suggested Filename(s): body-temp.cpp, multif-ifladder.cpp



Share

Created: 27-Dec-2017 18:26 | Updated: 15-Sep-2018 11:52|