Control structure: if / else

The number 0 is false; every other number is true, even negative numbers.

1
2
3
4
5
6
7
8
9
10
11
12
// test if: 0 is false all other numbers are true
#include <iostream>
using namespace std;
int main() {
  double num; // this will also work with int
  cout<<"Enter number to test:";
  cin>>num;
  if (num) cout<<num<<" is true\n";
  else cout<<num<<" is false\n";
  system("pause");
  return 0;
} //main
CODE

if
false
Try this simple program to verify that negative numbers are true.

NEXT: Not for negation