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

void Input(double cell_num, double relays, int & call_length);
void Output(double cell_num, double relays, double call_length, double net_cost, double call_tax, double total_cost);
void Process(double relays, double call_length, double net_cost, double call_tax, double total_cost);

void Input(double cell_num, double relays, double call_length)
{
   cout << "Enter your seven digit cell phone number.\n";
   cin >> cell_num;
   cout << "Enter the number of relay stations.\n";
   cin >> relays;
   cout << "Enter the number of minutes used to the nearest minute.\n";
   cin >> call_length;
}


void Output(double cell_num, double relays, double call_length, double net_cost, double call_tax, double tax_rate, double total_cost)
{
   if ((relays >= 1) && (relays <= 5))
      tax_rate = .01;
   else if ((relays >= 6) && (relays <= 11))
      tax_rate = .03;
   else if ((relays >= 12) && (relays <= 20))
      tax_rate = .05;
   else if ((relays > 21) && (relays <= 50))
      tax_rate = .08;
   else if (relays > 50)
      tax_rate = .12;                 // lines 39-48 used to assign taxation.

   net_cost = (relays / 50 * .4 * call_length);
   call_tax = net_cost * tax_rate;
   total_cost = net_cost + call_tax;

   cout.setf(ios::fixed);
   cout.setf(ios::showpoint);
   cout.precision(2);
}

void Process(double cell_num, double relays, double call_length, double net_cost, double call_tax, double total_cost)
{
   cout << "Callers Info               Calculated output\n";
   cout << "============================================\n";
   cout << "Cell phone:            " << cell_num;
   cout << "\nRelay Stations:            " << relays;
   cout << "\nMinutes Used:            " << call_length;
   cout << "\nNet Cost:            " << net_cost;
   cout << "\nCall Tax:            " << call_tax;
   cout << "\nTotal cost:            " << total_cost;
}

int main()
{
   double cell_num=0;
   double relays = 0;
   double  call_length = 0;
   double net_cost = 0;
   double call_tax = 0;
   double tax_rate = 0;
   double total_cost = 0;

   Input(cell_num, relays, call_length);
   Process(relays, call_length, net_cost, call_tax, total_cost);
   Output(cell_num, relays, call_length, net_cost, call_tax, total_cost);

   return 0;
}

Pretty new to functions in general and not understanding the errors I am getting. I had a working program but i tried to organize it into functions and i cant get it to work properly. if someone could help me and explain why certain changes are needed so i can fix in future i would greatly appreciate it.

R Sahu
  • 204,454
  • 14
  • 159
  • 270
  • 5
    which error do you have? – Matriac May 17 '16 at 03:32
  • 2
    My crystal ball is unable to even detect the kind of error you're getting: compile-time errors, run-time errors, or simply incorrect behaviour. If you're getting errors, please provide the ***actual error***. _You should have made that part of the title of your question!_ However, I can tell you your calculations will be done using zero values. _Always fun to divide by zero ;)_ And at least one of your redundant forward declarations doesn't match the implementation signature. – Disillusioned May 17 '16 at 03:45
  • Error LNK2019 unresolved external symbol "void __cdecl Process(double,double,double,double,double)" (?Process@@YAXNNNNN@Z) referenced in function _main cost_calculator_2 c:\Users\richard\documents\visual studio 2015\Projects\cost_calculator_2\cost_calculator_2\cost_calculator_2.obj 1 – Richard Buzbee May 17 '16 at 03:47
  • Please [edit](http://stackoverflow.com/posts/37266606/edit) that information into your question. But it does reveal a second mismatch between forward declaration signature and implementation signature. And your **main** method is calling the the one that isn't implemented. – Disillusioned May 17 '16 at 03:50
  • Note, the duplicate is the top result if you search this site for: "c++ unresolved external symbol" – Disillusioned May 17 '16 at 04:00

3 Answers3

2

You declare Process taking 5 doubles:

void Process(double relays, double call_length, double net_cost, double call_tax, double total_cost);

but you define it for 6 doubles:

void Process(double cell_num, double relays, double call_length, double net_cost, double call_tax, double total_cost)

So when you call the 5 double version, the compiler sees that it's declared (which is all the compiler needs), but when the linker goes to find the definition, it can't find it.

You also have the same style problem with Output.

xaxxon
  • 19,189
  • 5
  • 50
  • 80
1

First of all remove the first line:

# include "stdafx.h"

Refer to this answer to see why you should remove it: Fatal error: 'stdafx.h' file not found

Next, two of your function calls are missing arguments, in main() you called:

Process(relays, call_length, net_cost, call_tax, total_cost);

Output(cell_num, relays, call_length, net_cost, call_tax, total_cost);

Process takes 6 arguments but you are only passing 5, Output takes 7 argument but you are only passing 6.

Community
  • 1
  • 1
sj47sj
  • 185
  • 6
0

In addition to your function declarations not matching your definitions, which actually doesn't matter too much in this case, your definition for Input doesn't take references or pointers, as a result you are passing by value and you will get nothing out of it.

Since your functions are defined before they are used you don't actually need the declarations at the top. But your calls must match your definitions, which they do not. Hence the unresolved function error.

KeithLM
  • 38
  • 4
  • yeah i just noticed i am getting returned all zeroes for answers. i am getting confused the further i delve into writing this. how do i straighten it out so i get the real numbers not zeroes? – Richard Buzbee May 17 '16 at 04:44
  • In this case you can simply use references. Change your Input definition like this: void Input(double &cell_num, double &relays, double &call_length) – KeithLM May 17 '16 at 15:15