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

visual C++ not sure what I am doing to get these errors

本文关键字:错误 什么 不确定 C++ 视觉      更新时间:2023-10-16
# 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 outputn";
   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;
}

一般功能很新,不了解我遇到的错误。 我有一个工作程序,但我试图将其组织成函数,但我无法让它正常工作。如果有人可以帮助我并解释为什么需要某些更改以便我将来可以修复,我将不胜感激。

你声明过程需要 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 双精度版本时,编译器会看到它已声明(这是编译器需要的全部内容(,但是当链接器去查找定义时,它找不到它。

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

首先删除第一行:

# include "stdafx.h"

请参阅此答案以了解为什么要删除它:致命错误:"stdafx.h"文件未找到

接下来,你的两个函数调用缺少参数,在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 个参数。

除了你的函数声明与你的定义不匹配(在这种情况下实际上并不重要(之外,你的 Input 定义不接受引用或指针,因此你通过值传递,你不会从中得到任何东西。

由于您的函数在使用之前就已定义,因此您实际上不需要顶部的声明。 但是您的调用必须与您的定义匹配,而它们不符合。 因此,未解决的功能错误。

相关文章: