Professional Documents
Culture Documents
Exercise W6Answer
Exercise W6Answer
Name : ______________________________________________________
Matric: _______________________________
Group:________________________________
x=12;
if (x > 0)
{
jumlah = jumlah + x;
12
cout<<jumlah<<endl;
}
cout<<”jumlah = “<<jumlah;
output
12
jumlah = 12
2. Trace output for if statement bellow :
jumlah = 0;
0
x=12;
y=9;
if (x > y)
{
jumlah = jumlah + y;
9
cout<<jumlah<<endl;
}
if (x > 2)
{
jumlah = jumlah + x;
21
cout<<jumlah<<endl;
}
cout<<”jumlah = “<<Jumlah;
Output
9
21
Jumlah = 21
Output
if (temperature < 37)
cout<<”healthy”;
Output
if (age > 50)
{
cout<<”Do the following test :”<<endl;
cout<<”1) Blood test”<<endl;
cout<<”2) Blood pressure test”<<endl;
cout<<”3) Sugar test”<<endl;
}
Output
Girls
output
Here I am!
No, actually, I’m here!
b) Display “you are allowed to sit for final exam” if attendance is more
than 80 percent, otherwise display “you are not allowed to sit for final
exam”;
output
if (attendance > 80 )
cout<<” you are allowed to sit for final exam”;
else
cout<<” you are not allowed to sit for final exam”;
output
if ( y == 100 )
x = 1;
else
x = 0;