Lesson 07 - If-else-else if මොකද කරන්නේ

කන්ඩිෂන් එකක් පිලිපදිමින් interactive output දෙන්න ඉෆ් else else if භාවිතා කරන්න පුලුවන්.

>     විශාලද?                12 > 10 is TRUE
<     කුඩාද?                 2 < 5 is TRUE
>=    විශාල හෝ සමානද?       4 >= 4 is TRUE
<=    කුඩා හෝ සමානද?        3 <= 4 is TRUE
==    සමානද?                33 == 33 is TRUE
!=    අසමානද?               11 != 4 is TRUE

මූලික syntax එක,

if ( TRUE ){
  මෙම statement එක execute කරන්න.
}
else if(TRUE){
  මේවා execute කරන්න.
}
else{
 මේවා execute කරන්න.
}

[youtube https://www.youtube.com/watch?v=qKbGWYGfz14]

උදා:

#include <iostream>
using namespace std;

int main(){
int mark;
cout << "What mark did you get in the test?" << endl;
cin >> mark;

if(mark>100){
cout << "Invalid mark" << endl;
return -1;
}

if(mark >= 90)
{
cout << "You got an A*" << endl;
cout << "You Passed!" << endl;
}
else if(mark >= 75)
{
cout << "You got an B" << endl;
cout << "You Passed!" << endl;
}
else if(mark >= 60 )
{
cout << "You got an C" << endl;
cout << "You Passed!" << endl;
}
else if(mark >= 50)
{
cout << "You got an D" << endl;
cout << "You Passed!" << endl;
}
else
{
cout << "You got an E" << endl;
cout << "You Failed!" << endl;
}

return 0;
}