gpt4 book ai didi

c++ - 未定义的函数引用 (c++)

转载 作者:太空宇宙 更新时间:2023-11-04 15:35:48 24 4
gpt4 key购买 nike

我在问之前搜索了这个问题,我发现每个人都在使用 .h 文件来实现他们的功能,而我的老师教我们将 main 和功能放在一个文件中。

我只是想弄清楚为什么它是未定义的。我知道此代码中可能还存在其他问题,但我真的无法弄清楚我做错了什么。

这是我的代码:

#include <iostream>
#include <iomanip>

using namespace std;

void start();
void process();
void check();
void deposit();

const float dserv = 0.10;
const float cserv = 0.15;
const float fiveserv = 5.0;
const float oserv = 10.0;

int main()
{
float balance;
float amount;
bool fivehun;
bool endcheck;
float servcharge;
float servchargetotal;
char type;

start();
while(endcheck != true)
{process();}
cout<<"Current balance: $"<<balance<<endl;
cout<<"Total service charges: $"<<servchargetotal<<endl;
cout<<"Final balance: $"<<
system("pause");
return 0;
}

void start(float balance)
{
balance = 0;
cout<<fixed<<showpoint<<setprecision(2);
cout<<"Transactions will take the form of a letter followed by a dollar ";
cout<<"amount. Valid letters are “C” for a check, “D” for a deposit, and";
cout<<"“E” for the ending transaction (use zero on this transaction).";
cout<<"Press <Enter> after each line of input";
cout<<"Enter the beginning balance:"<<endl;
cin>>balance;
}

void process(float balance, float amount, char type, bool endcheck)
{
cout<<"Enter a transaction:"<<endl;
cin>>type>>amount;
if (type = "C"||"c")
{check();
endcheck = false;}
else if(type = "D"||"d")
{deposit();
endcheck = false;}
else if(type= "E"||"e")
{endcheck = true;}
}

void check(float balance, float amount, bool fivehun, float servcharge, float& servchargetotal)
{
balance = balance - amount;
servcharge = cserv;
if (balance<500.00)
{fivehun = true;}
else
{fivehun = false;}

cout<<"Transaction: Check in amount of $"<<amount<<endl;
cout<<"Current balance: $"<<balance<<endl;
cout<<"Service charge: Check - $"<<cserv<<endl;
if (fivehun == true)
{cout<<"Service charge: Below $500 - $"<<fiveserv<<endl;
servcharge = (fiveserv+servcharge);}
cout<<"Total service charges: $"<<servcharge<<endl;
servchargetotal = servchargetotal + servcharge;
}

void deposit(float balance, float amount, bool fivehun, float servcharge, float& servchargetotal)
{
balance = balance + amount;
servcharge = dserv;
if (balance<500.00)
{fivehun = true;}
else
{fivehun = false;}

cout<<"Transaction: Deposit in amount of $"<<amount<<endl;
cout<<"Current balance: $"<<balance<<endl;
cout<<"Service charge: Check - $"<<cserv<<endl;
if (fivehun == true)
{cout<<"Service charge: Below $500 - $"<<fiveserv<<endl;
servcharge = (fiveserv+cserv);}
cout<<"Total service charges: $"<<servcharge<<endl;
servchargetotal = servchargetotal + servcharge;
}

如果有任何我可以详细说明的地方,我会尽我所能进行编辑/评论。

最佳答案

检查你的 start 功能,如 M.M.你应该得到这样的东西:

float start() {
// ...
float balance;
cin >> balance;
return balance;
}


int main() {
float n;
n = start();
// ...
return 0;
}

并逐步检查所有函数,因为您在下一个 process 函数中遇到问题:in if statement must be comparison operator if (type == "C"|| type == "c") 而不是赋值 type = "C"||"c"

关于c++ - 未定义的函数引用 (c++),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34147549/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com