我是一名学生,其任务是创建一个程序,以确定一个人是否富裕。我的代码在下面,我不断收到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;
}
}
答案 0 :(得分:1)
声明isRich()
后,您有一个额外的分号。
您的代码应该如下所示:
...
bool isRich(int *age, long *cash, int *dependants, long *debt)
{
...
此外,在}
声明之前,您在函数calcWealth()
末尾错过了结束isRich()
。
答案 1 :(得分:0)
减去cin
语句,前几行看起来像
void calcWealth(int age, long cash, int dependants, long debt)
{
// ...
bool isRich(int *age, long *cash, int *dependants, long *debt);
{
但您无法在 isRich
内宣布calcWealth
。您需要告诉编译器第一个函数已完成,并使用}
。
作为参考,如果您有编译错误,它会附带一个行号。通过不显示它失败的行,你要求每个人猜测编译器已告诉你的东西。