所以我一直在研究这个非常简单的C ++分配,我在2个实例中出现了这个错误:'错误5错误C2371:'继电器' :重新定义;不同的基本类型'和'错误5错误C2371:' call_length' :重新定义;不同的基本类型'。我一直在查看该计划一个多小时,但我还没有看到这个问题,所以任何帮助都会受到欢迎。
以下代码:
#include <iostream> //standard input/output C++ stream library
#include <string> //string library
using namespace std; //using the standard C++ namespace
// function prototypes
void input(string &, int &, int &);
void process(double &, double &, double &, double &, int, int);
void output(string, int, int, double, double, double);
/////////////////////////////////////////////////////////////////
// Function name: input
// Precondition:
// Postcondition:
// Function Description:
////////////////////////////////////////////////////////////////
void input(string & cell_num, int & relays, int & call_length)
{
cout << "Enter your Cell Phone Number: ";
cin >> cell_num;
cout << "Enter the number of relay stations: ";
cin >> relays;
cout << "Enter the length of the call in minutes: ";
cin >> call_length;
}
/////////////////////////////////////////////////////////////////
// Function name:
// Precondition:
// Postcondition:
// Function Description
////////////////////////////////////////////////////////////////7
void process(double & tax_rate, double & call_tax, double & total_cost, double & net_cost, int relays, int call_length)
{
if (1<= relays <=5)
{
tax_rate = .01;
}
else if(6 <= relays <= 11)
{
tax_rate = .03;
}
else if(12<= relays <=20)
{
tax_rate = .05;
}
else if (21<= relays <=50)
{
tax_rate = .08;
}
else if (relays > 50)
{
tax_rate = .12;
}
net_cost = (relays / 50.0 * 0.40 * call_length);
call_tax = net_cost * tax_rate / 100;
total_cost = net_cost + call_length;
}
/////////////////////////////////////////////////////////////////
// Function name:
// Precondition:
// Postcondition:
// Function Description
////////////////////////////////////////////////////////////////
void output(string cell_num, int relays, int call_length, double net_cost, double total_cost, double call_tax)
{
cout << "*********************************" << endl;
cout << "Cell Phone Number: " << cell_num << endl;
cout << "*********************************" << endl << endl << endl;
cout << "Number of Relay Stations: " << relays << endl;
cout << "Length of Call in Minutes: " << call_length << endl;
cout << "Net Cost of Call: " << net_cost << endl;
cout << "Tax of Call: " << call_tax << endl;
cout << "Total Cost of Call: " << total_cost << endl;
}
int main()
{
string cell_num;
int call_length, relays;
double tax_rate, call_tax, net_cost, relays, call_length, total_cost;
input(cell_num, relays, call_length);
process(tax_rate, call_tax, total_cost, net_cost, relays, call_length);
output(cell_num, relays, call_length, net_cost, total_cost, call_tax);
system("pause");
return 0;
}
答案 0 :(得分:3)
在main中的这些语句中,首先定义call_length和relay两次作为int类型的变量,然后定义为double类型的变量。
int call_length, relays;
double tax_rate, call_tax, net_cost, relays, call_length, total_cost;
考虑到函数声明,似乎应将这些变量定义为类型为int。
答案 1 :(得分:1)
如错误消息所示:您已将变量relays
定义了两次。一次作为int,一次作为double。