[ create a new paste ] login | about

Link: http://codepad.org/fyHXAVZv    [ raw code | output | fork ]

kinopiko - C++, pasted on Nov 7:
#include <iostream>
#include <string>
#include <iomanip>

using std::cout;
using std::cin;
using std::endl;
using std::string;
using std::fixed;
using std::setprecision;

    //function prototypes
    void getInput (string &, int &, int &);
    void calcBill ( int, int, double, int &, double &);
    void displayBill (string, int, double);

int main ()

{
    //declare constant and variables
    const double RATE = .00175;
    string name       = "";
    int current       = 0;
    int previous      = 0;
    int gallons       = 0;
    double charge     = 0.0;

     //display output in fixed-point notation
    //with two decimal places
    cout << fixed << setprecision (2) ;

    //call functions to get input and
    //calculate and display water bill
    getInput   (name, current, previous);
    calcBill   (current, previous, RATE, gallons, charge);
    displayBill (name, gallons, charge);

    return 0;
}   //end of main function

    //*****function definitions*****
    void getInput (string &cust, int &cur, int &prev)
    {
        //gets the customer information
        cout << "Customer name: ";
        getline (cin, cust);
        cout << "Current reading: ";
        cin >> cur;
        cout << "Previous reading: ";
        cin >> prev;

   }    //end of getInput function

   void calcBill(int c, int p, double r, int &gal, double &due)

   {    
        //calculates gallons used and amount due
        gal = c - p;
        due = static_cast<double>(gal) * r;

   }    //end of calcBill function

   void displayBill(string cust, int used, double amtDue)

   {    //displays the water bill
        cout <<endl;
        cout << "Customer name: " << cust << endl;
        cout << "Gallons used: " << used << endl;
        cout << "Water charge: $" << amtDue << endl;

    }   //end of displayBill function


Output:
1
2
3
4
Customer name: Current reading: Previous reading: 
Customer name: 
Gallons used: 0
Water charge: $0.00


Create a new paste based on this one


Comments: