Use function parameters - C++ Function

C++ examples for Function:Function Parameter

Description

Use function parameters

Demo Code

#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;

double square(double doubleVar){
    return doubleVar * doubleVar;
}

void displayExplanation(void)
{
    cout << "Terminate the series by entering an\n"
         << "empty sequence.\n"
         << endl;/*  w ww  . ja  v  a  2s. c  om*/
    return;
}

double sumSquareSequence(void){
    double accumulator = 0.0;

    for(;;){
        double dValue = 0;
        cout << "Enter next number: ";
        cin  >> dValue;

        if (dValue < 0){
            break;
        }
        double value = square(dValue);
        accumulator += value;
    }
    return accumulator;
}

int main(int nNumberofArgs, char* pszArgs[])
{
    displayExplanation();
    for(;;)
    {
        cout << "Enter next sequence" << endl;
        double accumulatedValue = sumSquareSequence();

        if (accumulatedValue <= 0.0){
            break;
        }
        cout << "\nThe total of the values squared is " << accumulatedValue << endl << endl;
    }
    return 0;
}

Result


Related Tutorials