Strukturat e zgjedhjes " if " dhe " if … else "
Shembull per strukturen if else:
Lexohet nga tastiera numri i pikeve te testit dhe afishohet nota perkatese.
#include <iostream>
using namespace std;
int main()
{
int p;
cout <<"Jepni numrin e pikeve"<<endl;
cin>>p;
if (p<=44)
cout<<"Nota eshte 4"<<endl;
else if (p<=54)
cout<<"Nota eshte 5"<<endl;
else if (p<=64)
cout<<"Nota eshte 6"<<endl;
else if (p<=74)
cout<<"Nota eshte 7"<<endl;
else if (p<=84)
cout<<"Nota eshte 8"<<endl;
else if (p<=94)
cout<<"Nota eshte 9"<<endl;
else
cout<<"Nota eshte 10"<<endl;
system ("pause");
return 0;
}
Operatori kushtezues ( ? : ) – operator trinar (tre operande) fq 118
Zevendeson strukturen if else
psh:
nota>=60?cout<<”Kalon”<<endl : cout <<”Nuk kalon”<<endl;
ose
cout<< (nota>60) ? ”kalon” : ”nuk kalon”;
Shembull per operatorin kushtezues:
# include <iostream>
using namespace std;
int main()
{
int count = 1 ;
while (count <=10)
{
cout <<(count %2 ? "****":"++++++++")<<endl;
++count;
}
return 0;
}
Printon:
****
++++++++
****
++++++++
****
++++++++
****
++++++++
****
++++++++
Press any key to continue . . .