lundi 19 septembre 2016

functions in C++ [duplicate]

This question already has an answer here:

I am trying to make a program in C++ that will use one function (CalculateCharge) in order to determine a shipping cost. The total that shows up after I run the program is not what I was looking for. I just need some help to see what I did wrong.

This is what I have so far:

#include "stdafx.h"
#include <iostream>
using namespace std;

double CalculateCharge(int dist, int rate);

int dist, weight;
double rate;


int main()
{
    cout << "Enter the distance to be shipped (in miles): ";
    cin >> dist;
    cout << "Enter the weight of the package (in kilograms): ";
    cin >> weight;

    if (weight <= 2)
    {
        rate = 3.1;
        cout << "The price is " << "$" << CalculateCharge << endl;
        system ("pause");
    }
    else if (weight < 6 && weight > 2)
    {
        rate = 4.2;
        cout << "The price is " << "$" << CalculateCharge << endl;
        system ("pause");
    }
    else if (weight < 10 && weight > 6)
    {
        rate = 5.3;
        cout << "The price is " << "$" << CalculateCharge << endl;
        system ("pause");
    }
    else if (weight > 10)
    {
        rate = 6.4;
        cout << "The price is " << "$" << CalculateCharge << endl;
        system ("pause");
    }
    else
    {
        cout << "This is an invalid input!" << endl;
        system ("pause");
    }


    return 0;
}

    double CalculateCharge(int dist, int rate)
    {
        double total;
        total = ((dist/500) * rate);
        return total;
    }

Aucun commentaire:

Enregistrer un commentaire