We are making some good progress into the framework on how programs store data and preform simple calculations.  Now lets introduce a way that our programs can make logical decisions based on conditions.

What is a condition?  A simple example is if is greater than a value, then perform and action.

/* Intro to IF Statements
   Part 1
   Nathan Neil */
   
   #include <iostream>
   
   using namespace std;
   
   int main() {
   	
   	int a = 20;
   	int b;
   	
  	//Ask for a number
	cout << "Pick a number: ";
   	cin >> b;
   	
   	if (a > b) {
   		cout << "A is greater than B";
	   }
	if (a < b) {
   		cout << "A is less than B'";
	   }
	if (a == b) {
   		cout << "A Equals B";
	   }	

   	return 0;
   	
   	
   }

 

Pin It on Pinterest

Share This

Share this post with your friends!

%d bloggers like this: