C ++不确定我在做什么来获取这些错误

时间:2016-05-17 03:30:17

标签: c++ visual-c++

# 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;
}

一般来说功能很新,而不是理解我得到的错误。我有一个工作程序,但我试图将其组织成功能,我不能让它正常工作。如果有人可以帮助我并解释为什么需要进行某些更改,以便我将来能够解决这个问题,我会非常感激。

3 个答案:

答案 0 :(得分:2)

你声明过程需要5个双打:

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

但你定义了6个双打:

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

因此,当您调用5双版本时,编译器会看到它已声明(这是编译器需要的所有内容),但是当链接器找到定义时,它无法找到它。

输出也存在相同的样式问题。

答案 1 :(得分:1)

首先删除第一行:

# include "stdafx.h"

请参阅此答案,了解您应将其删除的原因: Fatal error: 'stdafx.h' file not found

接下来,您调用的main()中有两个函数调用缺少参数:

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

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

进程需要6个参数,但是你只传递5个,输出需要7个参数,但你只传递6个。

答案 2 :(得分:0)

除了您的函数声明与您的定义不匹配(在这种情况下实际上并不重要),您对Input的定义不会引用或引用,因此您传递的是值你将从中得不到任何东西。

由于您的功能在使用之前已经定义,因此您实际上并不需要在顶部进行声明。但是你的电话必须符合你的定义,而他们却没有。因此未解决的功能错误。