Use if statement to check value range - C++ Statement

C++ examples for Statement:if

Introduction

The syntax for an if statement is:

if (expression){ 
   statements 
}elseif (expression){ 
   statements 
}elseif (expression){ 
   statements 
}else{ 
   statements 
} 

Demo Code

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

int main () { //from ww  w  . j  a  v a  2s.co  m

    int mark ; 
    cout << " What was your average mark ?\n"; 
    cin >> mark ; 

    if ( mark >= 70) { 
       cout << " Congratulations !\n"; 
       cout << " You got a distinction .\n"; 
    } 
    else if ( mark >= 60) { 
       cout << " Well done !\n"; 
       cout << " You got a merit !\n"; 
    } 
    else if ( mark >= 50) { 
       cout << " You passed .\n"; 
    } 
    else { 
       cout << " You failed : -(\n"; 
    } 
    return 0; 
} 

Result


Related Tutorials