User Defined Functions
Jan 29, 2015 at 5:30am UTC
In my class I am supposed to write a program with user defined constants and user defined functions. We are given tuition cost of $50 per credit hour and a one time technology fee of $10. I am stuck on how to implement/call user defined functions.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
#include "stdafx.h"
const double TECHFEE = 10.00,
CREDITCOST = 50.00; //User defined constants?
int _tmain(int argc, _TCHAR* argv[])
{
double credits = 0,
cost;
cout << "Please enter the number of credits you wish to take: " ;
cin >> credits;
cout << endl;
totalCost(TECHFEE,CREDITCOST,credits);
cout << " The total tuition cost this semester is " << cost;
system("PAUSE" );
return 0;
}
double totalCost(double TECHFEE, double CREDITCOST, double credits)
{
double cost = 0;
cost = (CREDITCOST * credits) + TECHFEE;
return cost;
}
//I feel as though this whole defined function is typed incorrectly.
Last edited on Jan 29, 2015 at 5:30am UTC
Jan 29, 2015 at 5:38am UTC
try changing line 14
totalCost(TECHFEE,CREDITCOST,credits);
to
cost = totalCost(TECHFEE,CREDITCOST,credits);
Jan 29, 2015 at 5:42am UTC
It says totalCost identifier not found. Was I supposed to make a prototype somewhere?
Jan 29, 2015 at 5:44am UTC
Yes, before int main()
put
double totalCost(double TECHFEE, double CREDITCOST, double credits);
Jan 29, 2015 at 5:53am UTC
Edit: Nevermind I figured it out! Thanks again Pin!
Last edited on Jan 29, 2015 at 6:00am UTC
Topic archived. No new replies allowed.