D
Danny
Hi
Could somone please criticise the following program, it went together
far to easily (bearing in mind i am just getting into c++) **note the
tabs are not as they appear in my compliler**
Dan
/* This program will calculate the cost of running an electric appliance
over several different time spans*/
#include <iostream>
#include <ostream>
using namespace std;
double unit = 0; // unit cost of electricity
double rate = 0; // the rating of the appliance
double hours = 0; // number of hours per day
double days = 0; // number of days per week
double weeks = 0; // number of weeks a month
double months = 0; // number of months a year
double years = 0; // number of years
double cost = 0; // cost of the appliance
double calculate(double uni, double rat, double hour, double day, double
week, double month, double year);
int main ()
{
cout << "The program has begun!" << "\n"; // indicates the program is alive
{ // obtains initial values
cout << "Enter the unit cost of electricity (pence): ";
cin >> unit;
cout << "\n";
cout << "Enter the rating of the appliance (Kilo Watts): ";
cin >> rate;
cout << "\n";
cout << "Enter the number of hours: ";
cin >> hours;
cout << "\n";
cout << "Enter the number of days: ";
cin >> days;
cout << "\n";
cout << "Enter the number of weeks: ";
cin >> weeks;
cout << "\n";
cout << "Enter the number of months: ";
cin >> months;
cout << "\n";
cout << "Enter the number of years: ";
cin >> years;
cout << "\n";
cout << "The total cost over the specified time span is: " <<
calculate(unit, rate, hours, days, weeks, months, years) << " pence" <<
"\n";
}
return 0;
}
// Function to do the specific calculation
double calculate(double uni, double rat, double hour, double day, double
week, double month, double year)
{
cost = uni * (((((rat * hour) * day) * week) * month) * year);
return cost;
}
Could somone please criticise the following program, it went together
far to easily (bearing in mind i am just getting into c++) **note the
tabs are not as they appear in my compliler**
Dan
/* This program will calculate the cost of running an electric appliance
over several different time spans*/
#include <iostream>
#include <ostream>
using namespace std;
double unit = 0; // unit cost of electricity
double rate = 0; // the rating of the appliance
double hours = 0; // number of hours per day
double days = 0; // number of days per week
double weeks = 0; // number of weeks a month
double months = 0; // number of months a year
double years = 0; // number of years
double cost = 0; // cost of the appliance
double calculate(double uni, double rat, double hour, double day, double
week, double month, double year);
int main ()
{
cout << "The program has begun!" << "\n"; // indicates the program is alive
{ // obtains initial values
cout << "Enter the unit cost of electricity (pence): ";
cin >> unit;
cout << "\n";
cout << "Enter the rating of the appliance (Kilo Watts): ";
cin >> rate;
cout << "\n";
cout << "Enter the number of hours: ";
cin >> hours;
cout << "\n";
cout << "Enter the number of days: ";
cin >> days;
cout << "\n";
cout << "Enter the number of weeks: ";
cin >> weeks;
cout << "\n";
cout << "Enter the number of months: ";
cin >> months;
cout << "\n";
cout << "Enter the number of years: ";
cin >> years;
cout << "\n";
cout << "The total cost over the specified time span is: " <<
calculate(unit, rate, hours, days, weeks, months, years) << " pence" <<
"\n";
}
return 0;
}
// Function to do the specific calculation
double calculate(double uni, double rat, double hour, double day, double
week, double month, double year)
{
cost = uni * (((((rat * hour) * day) * week) * month) * year);
return cost;
}