C++: The if-else statement

This entry is part 11 of 61 in the series C++

The if…else statement allows you to specify an action to perform when the condition is true and a different action to perform when the condition is false.

#include <iostream>
#include <string>
using namespace std;

void main()
{
	int grade = 70;

	if (grade >= 60)
		cout << "Passed";
	else
		cout << "Failed";

	cout << endl;
}

In the above code line 9 will evaluate to true and so the string Passed will be printed out.

ifelse

 

 

 

Series Navigation<< C++: Flow control with if statement
C++: The while loop >>

Leave a comment

Leave a Reply