Page 16 - مجلة طموح IT
P. 16
// i/o example Please enter an integer value: 702 The
#include <iostream> value you entered is 702 and its
using namespace std; double is 1404.
int main ()
{
int i;
cout << "Please enter an integer value:
"; cin >> i;
cout << "The value you entered is " <<
i; cout << " and its double is " << i*2
<< ".\n"; return 0;
}
الجمل الشرطي ٌة
في البرمجة نستطي ٌع تنفي ٌذ كود معي ٌن اذا تحقق شرط معي ٌن وي ٌمكن عمل ذلك باستخدام الكلمة
يغة العامة لهاiصf المفتاحية وال
if (condition) statement
هو الشرط الذي سيتٌم التحقق منه اذا كان صائبا سيتٌم تنف ٌذ الجلة او مجموعة الجمل و ٌجب وضعه بي ٌن اقواسcondition حي ٌث
if (x == 100) else استخدام
cout << "x is 100"; في بعض الاحياٌن نر ٌد ان ٌتي تنف ٌذ كود مع ٌن اذا تحقق الشرط واذا لم تٌحقق ننفذ كود اخر
if (x == 100) 16
cout << "x is 100";
else
cout << "x is not 100";
if (x > 0)
cout << "x is positive";
else if (x < 0)
cout << "x is negative";
else
cout << "x is 0";

