cplusplus:selection_examples
This is an old revision of the document!
Table of Contents
Control Structures: Selection examples
if
- if_example.cpp
/* Using if statements */ #include <iostream> using namespace std; int main() { int grade; cout << "Enter a grade and I will tell you if you passed: "; cin >> grade; if (grade > 60) cout << "Passed!" << endl; return 0; }
if/else
- if_else_example.cpp
/* Using if/else statements */ #include <iostream> using namespace std; int main() { int num1; cout << "Enter an integer, and I will tell you "; cout << "if the number is positive: "; cin >> num1; // read an integer if (num1 > 0) cout << num1 << " is positive. "<< endl; else cout << num1 << " is not positive. "<< endl; return 0; }
Nested if/else
cplusplus/selection_examples.1359859851.txt.gz · Last modified: 2013/02/03 02:50 by mithat