[英]Error saying, “statement cannot resolve address of overloaded function”
I'm a beginner programmer, so this is going to look messy, but I keep getting the problem that is mentioned in the title. 我是一个初学者程序员,所以看起来有些混乱,但是我一直遇到标题中提到的问题。 No matter where I try to put
endl
; 无论在哪里我试图把
endl
; it keeps giving me the same error. 它一直给我同样的错误。 Also when I run the code my total for the second store comes out right but the first store total does not.
另外,当我运行代码时,我第二家商店的总数显示正确,而第一家商店的总数却不正确。 Any idea on how to fix this?
关于如何解决此问题的任何想法? I'm using codeblocks on a windows 7 computer.
我在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;
Did you try something like 你尝试过类似的东西吗
cout << "Total number of widgets at each store starting with :";
cin >> widgetStores;
cout << endl; //Added this
cin doesn't have a << operator, so you need to send it to cout. cin没有<<操作符,因此您需要将其发送给cout。
Edit: I found the error you're having. 编辑:我发现了您遇到的错误。 I guess that you are trying to put in lines as literally
我想您正在尝试按字面意思排成一行
endl;
ENDL;
and that doesn't go anywhere... 而且那无处不在...
The only compile error this program has, is that you're using widgetsLeftS1W1
, widgetsLeftS1W2
, widgetsLeftS2W1
and widgetsLeftS2W2
before initializing them. 该程序唯一的编译错误是,在初始化它们之前,您使用的是
widgetsLeftS1W1
, widgetsLeftS1W2
, widgetsLeftS2W1
和widgetsLeftS2W2
。
You probably need =
instead of -=
. 您可能需要
=
而不是-=
。
When you say 当你说
widgetsLeftS1W1 -= (widgetStore1-numberSoldFirst1);
what you actually mean is 你真正的意思是
widgetsLeftS1W1 = widgetsLeftS1W1 - (widgetStore1-numberSoldFirst1);
The computer doesn't know the value of widgetsLeftS1W1
, so it gives you the error. 计算机不知道
widgetsLeftS1W1
的值,因此会出现错误。
Conclusion: use 结论:使用
widgetsLeftS1W1 = (widgetStore1 - numberSoldFirst1);
Try initializing the values of 尝试初始化的值
widgetsLeftS1W1
widgetsLeftS1W2
widgetsLeftS2W1
widgetsLeftS2W2
with zero while declaring them at the top. 声明为顶部时为零。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.