Add parentheses to change the operator precedence - C++ Operator

C++ examples for Operator:Arithmetic Operator

Description

Add parentheses to change the operator precedence

Demo Code

#include <iostream>
using namespace std;
int main()/*from  ww w  . j a v a  2 s .c o m*/
{
   float avg, grade1, grade2, grade3;
   grade1 = 87.5;
   grade2 = 92.4;
   grade3 = 79.6;
   avg = (grade1 + grade2 + grade3) / 3.0;
   cout << "The average is " << avg << "\n";
   return 0;
}

Result


Related Tutorials