一切正常,直到它到底(void displayData())。我收到某种错误,说'int getLength(int&)'的地址总是评为'true' [英] Everything works fine, until it gets to the bottom on (void displayData()). I'm getting some kind of error saying, "the address of 'int getLength(int&)' will always evaluate as 'true'

查看:91
本文介绍了一切正常,直到它到底(void displayData())。我收到某种错误,说'int getLength(int&)'的地址总是评为'true'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include <iostream>
using namespace std;

int getLength(int&);
int getWidth(int&);
double getArea(double lengthNum, double widthNum);
void displayData();

int main(){
    int length, width; 

    
    getLength(length);
    getWidth(width);
    getArea(length, width);
    displayData();
    
    system("pause");
    return 0;
}

int getLength(int& lengthValue)
{
    
    
    cout << "Enter the length: ";
    cin >> lengthValue;
    
    if (lengthValue < 0)
    {
        cout << "\nERROR: Enter a positive number.\n";
        cout << "Enter the length: ";
        cin >> lengthValue;
        cout << endl;
    }
    return lengthValue;
}

int getWidth(int& widthValue)
{
   
    
    cout << "Enter the width: ";
    cin >> widthValue;
    
    if (widthValue < 0)
    {
        cout << "\nERROR: Enter a positive number.\n";
        cout << "Enter the width: ";
        cin >> widthValue;
        cout << endl;
    }
    return widthValue;
}

double getArea(double lengthNum, double widthNum)
{
    return lengthNum * widthNum;
}
//ERROR in here please HELP....Thanks in advance :)!
void displayData()
{
   
    cout << "Rectangle Data\n";
    cout << "--------------\n";
    cout << "Length: " << getLength << endl;
    cout << "Width: " << getWidth << endl;
    cout << "Area: " << getArea << endl;
}

推荐答案

一切都没有意义。当您编写操作数 getLength 时,您尝试输出什么,这是一个函数,但不是它的调用?你可能打算调用这个函数,但这可以通过 getLength(& someIntObject)来完成。



这个函数的签名也没有名称意义,抛开它的实现。如果要返回值,则需要返回它。您可以通过引用分配值,然后返回它。



此代码中的任何内容都没有任何意义。没有什么可以解决的。您需要回到编程的基础知识:变量,函数,参数传递方法,地址和指针等。尝试彻底阅读基本主题并理解它们;这是我现在可以提供的所有建议。



-SA
It all makes no sense at all. What are you trying to output when you write the operand getLength, which is a function, but not its call? You probably meant to call this function, but that could be done by getLength(&someIntObject).

The signature of this function also does not name sense, set aside its implementation. If you want to return value, you need just return it. You assign the value by reference and then also return it.

Nothing in this code makes any sense. There is nothing to fix. You need to go back to the very basics of programming: variables, functions, parameter passing methods, addresses and pointers, and so on. Try to read on the basic topics thoroughly and understand them; this is all I can advise at the moment.

—SA


这篇关于一切正常,直到它到底(void displayData())。我收到某种错误,说'int getLength(int&amp;)'的地址总是评为'true'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆