Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) IfExample1

 

STLQt CreatorWindows

 

if example 1: basics is an if example.

 

Technical facts

 

Operating system(s) or programming environment(s)

IDE(s):

Project type:

C++ standard:

Compiler(s):

Libraries used:

 

 

 

 

 

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...

*/

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict

This page has been created by the tool CodeToHtml