(C++) IfExample1
February 24, 2017 · View on GitHub
(C++) IfExample1



if example 1: basics is an if example.
Technical facts
Operating system(s) or programming environment(s)
Lubuntu 15.04 (vivid)
Qt Creator 3.1.1
- G++ 4.9.2
Libraries used:
STL: GNU ISO C++ Library, version
4.9.2
Qt project file: ./CppIfExample1/CppIfExample1.pro
TEMPLATE = app CONFIG += console CONFIG -= app_bundle CONFIG -= qt SOURCES += main.cpp CONFIG(release, debug|release) { DEFINES += NDEBUG NTRACE_BILDERBIKKEL } QMAKE_CXXFLAGS += -Wall -Wextra -Weffc++ unix { QMAKE_CXXFLAGS += -Werror } win32 { INCLUDEPATH += \ ../../Libraries/boost_1_54_0 }
./CppIfExample1/main.cpp
#include <cstdlib> #include <iostream> int main() { //Draw a random number const int x = std::rand(); std::cout << "Drew random number: " << x << '\n'; //If statement if (x == 42) { std::cout << "The value of x is the Answer to The Ultimate Question of Life, " << "the Universe, and Everything.\n"; } //If-else statement if (x % 2 == 0) { std::cout << "The value of x is even.\n"; } else { std::cout << "The value of x is odd.\n"; } } /* Screen output: Drew random number: 41 The value of x is odd. Press <RETURN> to close this window... */