c++ if else statements
[code language=”cpp”]
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char** argv) {
int a=5;//Declares an integer, and assigns a value.
if(a>10) {
cout << "This will never gets printed.\n";
} else {
cout << "a=5, 5 is not greater than 10.\n";
}
if(a<5) {
cout << "This will never gets printed.\n";
} else if(a>5) {
cout << "This will never gets printed.\n";
} else {
cout << "Correct, a is equal to 5.\n";
}
return 0;
}
[/code]
Output:
[code language=”text”]
a=5, 5 is not greater than 10.
Correct, a is equal to 5.
[/code]
Search within Codexpedia
Custom Search
Search the entire web
Custom Search
Related Posts