Control structure: if / else

The exclamation point, "!", means not.

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 false\n";
  else cout<<num<<" is true\n";
  system("pause");
  return 0;
} //main
CODE

if
false

if(grade<65) cout<<"fail"; else cout<<"pass";
if(grade>=65) cout<<"pass"; else cout<<"fail";

Notice that the opposite of grade<65 is grade>=65

It is important to test a program thoroughly. For this small piece of code you should test grades that are less than 65, greater than 65, and exactly 65 to make sure it works!

NEXT: Use ==, not =