您好我正在开发一个程序,用于将用户的价格输入存储到数组中。然后有一个模块接受价格数组和退税。这是我到目前为止所拥有的。我的模块一直在生产LNK2019。
#include <iostream>
using namespace std;
double PrArray[20] = {}, total_price, tax_rate, price, tax;
int i;
double TAXOWED();
void main()
{
cout << "input the sales tax rate as a decimal ";
cin >> tax_rate;
cout << "\nplease enter a price or 0 to quit ";
i = 0;
cin >> price;
PrArray[i] = price;
while (price > 0 && i < 19)
{
i++;
cout << "please enter a price or 0 to quit ";
cin >> price;
PrArray[i] = price;
}
for (i = 0; i < 19; i++)
{
cout << "\n";
cout << PrArray[i];
}
TAXOWED();
system("PAUSE");
return;
}
double TAXOWED(double PrArray[], int i)
{
double total_tax;
for (i = 0; i < 19; i++)
{
tax = tax_rate * PrArray[i];
total_tax = tax;
}
return(total_tax);
}
答案 0 :(得分:2)
您的函数声明和定义不匹配
// Declaration
double TAXOWED();
// Definition
double TAXOWED(double PrArray[], int i);
所以基本上你是在声明一个函数并且从不定义它,然后在下面定义一个单独的函数。
答案 1 :(得分:0)
转发您的评论,代码应如下所示:
#include <iostream>
using namespace std;
double TAXOWED(double price, double tax_rate)
{
return tax_rate * price;
}
int main()
{
double PrArray[20], total_tax[20], tax_rate, price;
cout << "input the sales tax rate as a decimal ";
cin >> tax_rate;
cout << "\nplease enter a price or 0 to quit ";
cin >> price;
if ( price == 0 )
return -1;
int i = 0;
PrArray[i] = price;
for (i = 1; i < 20; i++)
{
cout << "please enter a price or 0 to quit " ;
cin >> price;
PrArray[i] = price;
}
for (int i = 0 ; i < 20; i++)
total_tax[i] = TAXOWED(PrArray[i], tax_rate);
for (int i = 0; i < 20; i++)
cout << "Tax for price #" << i << " : " << total_tax[i] << endl;
system("PAUSE");
return 0;
}
此代码允许您为每个价格设置tax_rate
,每个price
值和输出tax_rate
。
答案 2 :(得分:0)
好的,这就是我现在拥有的。我需要最后的图表将所有总价格加在一起
#include <iostream>
using namespace std;
// declerations
double PrArray[20], total_tax[20], tax_rate, price, total_price;
int i;
double TAXOWED(double price, double tax_rate)
{
return tax_rate * price;
}
void main()
{
cout << "input the sales tax rate as a decimal ";
cin >> tax_rate;
cout << "\nplease enter a price or 0 to quit ";
i = 0;
cin >> price;
PrArray[i] = price;
while (price > 0 && i < 19)
{
i++;
cout << "please enter a price or 0 to quit ";
cin >> price;
PrArray[i] = price;
}
for (int i = 0; i < 20; i++)
{
total_tax[i] = TAXOWED(PrArray[i], tax_rate);
}
system("CLS");
cout << " Prices";
cout << "\ntaxrate % " << tax_rate;
cout << "\nprices tax Total price ";
cout << "\n__________________________________________________";
for (int i = 0; i < 20; i++)
{
cout << "\n" << PrArray[i] << " " << total_tax[i] << " " << PrArray[i] + total_tax[i];
}
for (int)
system("PAUSE");
return;
}