Using four double-precision variables, with the cout object used to display the contents of one of the variables. - C++ Data Type

C++ examples for Data Type:double

Description

Using four double-precision variables, with the cout object used to display the contents of one of the variables.

Demo Code

#include <iostream>
using namespace std;
int main()//  www  .  jav a 2  s  . c o m
{
   double grade1;   // declare grade1 as a double variable
   double grade2;   // declare grade2 as a double variable
   double total;    // declare total as a double variable
   double average;  // declare average as a double variable
   grade1 = 85.5;
   grade2 = 97.0;
   total = grade1 + grade2;
   average = total/2.0;  // divide the total by 2.0
   cout << "The average grade is " << average << endl;
   return 0;
}

Result


Related Tutorials