C++ Function Parameter double type

Description

C++ Function Parameter double type

#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;/*from w ww  . j av a 2  s .c  o m*/
    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;
}



PreviousNext

Related