试图编写函数的未定义标识符
Undefined identifier trying to write a function
我是一名学生,我的任务是创建一个程序来确定一个人是否富有。我的代码在下面,我一直得到一个错误,identifier "isRich" is undefined
。有人能告诉我哪里出错了吗?
#include "stdafx.h"
#include <iostream> //for input and output
#include "Cusick Project 5.h"
using namespace std;
void calcWealth(int age, long cash, int dependants, long debt)
{
cout << "Please enter your age: ";
cin >> age;
cout << "Please enter the amount of cash on hand: ";
cin >> cash;
cout << "Please enter the amount of dependents you have: ";
cin >> dependants;
cout << "Please enter the amount of money you owe";
cin >> debt;
bool isRich(int *age, long *cash, int *dependants, long *debt);
{
long trueCash;
bool status = false;
trueCash = cash - debt;
if (dependants == 0)
{
if (trueCash >= 1000000)
{
status = true;
}
else
status = false;
}
else if (age < 40)
{
trueCash = trueCash - (dependants * 150000);
if (trueCash >= 1000000)
{
status = true;
}
else
status = false;
}
else if (age > 39 && age < 51)
{
trueCash = trueCash - (dependants * 75000);
if (trueCash >= 1000000)
{
status = true;
}
else
status = false;
}
else
{
trueCash = trueCash - (dependants * 25000);
if (trueCash >= 1000000)
{
status = true;
}
else
status = false;
}
}
}
int main()
{
int age;
long cash;
int dependants;
long debt;
bool status;
cout << "Welcome to the wealth indicator..." << endl;
calcWealth(age, cash, dependants, debt);
if (isRich(status) = true)
{
cout << "Congratulations! We consider you as being "rich."" << endl;
}
else
{
cout << "I am sorry! You are not yet "rich."" << endl;
}
}
在isRich()
的声明后面有一个额外的分号。
你的代码应该看起来像:
...
bool isRich(int *age, long *cash, int *dependants, long *debt)
{
...
此外,在函数calcWealth()
的末尾,就在isRich()
的声明之前,您缺少一个关闭的}
。
减去cin
语句,您的前几行看起来像
void calcWealth(int age, long cash, int dependants, long debt)
{
// ...
bool isRich(int *age, long *cash, int *dependants, long *debt);
{
但是你不能在 calcWealth
中开始声明isRich
。您需要告诉编译器第一个函数已经完成,并使用}
。
顺便说一句,这个函数无论如何都不会做你想要的——它读取的值会丢失——但这是另一个问题。
作为参考,如果你有一个编译错误,它会附带一个行号。如果不显示它在哪一行出错,你就要求每个人猜测编译器已经告诉你的事情。
相关文章:
- Visual Studio C++ PlaySound 标识符未定义
- 删除动态数组时未定义标识符
- 未定义的标识符/未声明
- 标识符Class_name未定义C++ oop
- 标识符"hWnd"未定义
- 为什么更改包含 psapi.h 的顺序会产生编译错误?(标识符 BOOL 未定义)
- Visual Studio 2019 概念标识符未定义
- 标识符"DDRB"未定义 - VS code / Visual Studio
- 在头文件中使用opencv类型来实现未定义的标识符
- 标识符"in"未定义
- 智能感知:标识符"node"未定义
- 标识符"__readgsqword"未定义 - Visual Studio 2017
- 标识符"V 未定义
- 标识符"thread"未定义
- 标识符uint8_t未定义 - Visual Studio 2017
- 未定义的标识符 - 缺少哪些头文件?- DX12.
- 调用函数时未定义标识符"function_name"
- Wininet未定义标识符
- 简单代码问题-未定义标识符
- 试图编写函数的未定义标识符