簡體   English   中英

錯誤提示:“語句無法解析重載函數的地址”

[英]Error saying, “statement cannot resolve address of overloaded function”

我是一個初學者程序員,所以看起來有些混亂,但是我一直遇到標題中提到的問題。 無論在哪里我試圖把endl ; 它一直給我同樣的錯誤。 另外,當我運行代碼時,我第二家商店的總數顯示正確,而第一家商店的總數卻不正確。 關於如何解決此問題的任何想法? 我在Windows 7計算機上使用代碼塊。

#include <iostream> //Allows cout/cin
#include <ctime> //Allows time
#include <iomanip> //Allows setprecision

using namespace std;

int main()
{
    //Include header

    //Input variables
    double widgetStores;
    double numberSoldFirst1;
    double numberSoldFirst2;
    double numberSoldSecond1;
    double numberSoldSecond2;
    double widgetsLeftS1W2;
    double widgetsLeftS2W1;
    double widgetsLeftS2W2;

    //Start Clock
    clock_t begin, end;
    double time_spent;
    begin = clock();

    //Prompt for total number in stores

    cout << "Total number of widgets at each store starting with :";
    cin >> widgetStores;

    double widgetStore1=widgetStores;
    double widgetStore2=widgetStores;
    double widgetsLeftS1W1;


    //Prompt for amount sold during first and second week

    cout << "How many widgets were sold at Store 1 the first week? ";
    cin >> numberSoldFirst1;
    cout << "How many widgets were sold at Store 1 the 2nd week? ";
    cin >> numberSoldSecond1;
    cout << "How many widgets were sold at Store 2 the first week? ";
    cin >> numberSoldFirst2;
    cout << "How many widgets were sold at Store 2 the 2nd week? ";
    cin >> numberSoldSecond2;

    //Calculate Number of widgets
    widgetsLeftS1W1-=(widgetStore1-numberSoldFirst1);
    widgetsLeftS1W2-=(numberSoldFirst1-numberSoldSecond1);
    widgetsLeftS2W1-=(widgetStore2-numberSoldFirst2);
    widgetsLeftS2W2-=(numberSoldFirst2-numberSoldSecond2);

    //Display Values
    cout << "Store 1 has " << widgetsLeftS1W2 << " widgets left after the 2nd week.";
    cout << "Store 2 has " <<widgetsLeftS2W2 << " widgets left after the 2nd week.";

    //Show time elapsed
    end = clock();
    time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
    cout << setprecision(2) << fixed << "****Elapsed time:" <<time_spent/60 <<        "minutes****";
    return 0;

你嘗試過類似的東西嗎

cout << "Total number of widgets at each store starting with :";
cin >> widgetStores;
cout << endl; //Added this

cin沒有<<操作符,因此您需要將其發送給cout。

編輯:我發現了您遇到的錯誤。 我想您正在嘗試按字面意思排成一行

ENDL;

而且那無處不在...

該程序唯一的編譯錯誤是,在初始化它們之前,您使用的是widgetsLeftS1W1widgetsLeftS1W2widgetsLeftS2W1widgetsLeftS2W2

在此處輸入圖片說明

您可能需要=而不是-=

當你說

widgetsLeftS1W1 -= (widgetStore1-numberSoldFirst1);

你真正的意思是

widgetsLeftS1W1 = widgetsLeftS1W1 - (widgetStore1-numberSoldFirst1);

計算機不知道widgetsLeftS1W1的值,因此會出現錯誤。


結論:使用

widgetsLeftS1W1 = (widgetStore1 - numberSoldFirst1); 

嘗試初始化的值

widgetsLeftS1W1
widgetsLeftS1W2
widgetsLeftS2W1
widgetsLeftS2W2

聲明為頂部時為零。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM