473,382 Members | 1,657 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

"variable cannot be used as a function" error

I'm writing a very simple program, but I keep getting the same error, no matter what I do. What is it that is going wrong? It says I can't use the variable as a function.

Here is my code:

Expand|Select|Wrap|Line Numbers
  1. #include <iosrteam>
  2. using namespace std;
  3. int what;
  4. int main()
  5. {
  6.   int what;
  7.   cout << what(9,3,17) << endl;
  8. }
  9.  
  10. int what(int x, int y, int z)
  11. {
  12.     if(x>y && x>z)
  13.       return x;
  14.    if(y>x && y>z)
  15.      return y;
  16.    if(z>x && z>y)
  17.     return z;
  18.   else
  19.    return 0;
  20. }
  21.  
I feel like its a simple fix... help!
Feb 19 '16 #1
5 21027
weaknessforcats
9,208 Expert Mod 8TB
Starting from the top of the program, the first thing the compiler sees is:

Expand|Select|Wrap|Line Numbers
  1. int what;
The next thing the compiler sees is:

Expand|Select|Wrap|Line Numbers
  1. int main()
  2.  {
  3.  int what;
  4.  
This is a second variable named what but this one is local to main(). The int what outside of main is completely blocked by this local one.

Then the compiler sees:

Expand|Select|Wrap|Line Numbers
  1. cout << what(9,3,17) << endl;
  2.  
so you get an error trying to use variable as a function. There is a what function, but the compiler hasn't seen it yet.

YOu need a function prototype:

Expand|Select|Wrap|Line Numbers
  1. int what(int x, int y, int z);
  2.  
  3. int main()
  4. {
  5.     what(9,3,17);   // this is now OK
  6. }
The function prototype is the first line of the function definition ended by a semicolon. This tells the compiler there is a function what with 3 int arguments.

Lastly, never name your variables and your functions using the same name.
Feb 19 '16 #2
You also wrote #include <iostream> wrong
Jan 20 '20 #3
Ishan Shah
47 32bit
You have declared variable which name is the same as the function name, so that's why it will give you an error

Expand|Select|Wrap|Line Numbers
  1. int main()
  2. {
  3.   int what;
  4.   cout << what(9,3,17) << endl;
  5. }

if you want to declare the function, then you can write like the following code instead of that

Expand|Select|Wrap|Line Numbers
  1. int main()
  2. {
  3.   int what(int,int,int);
  4.   cout << what(9,3,17) << endl;
  5. }
  6.  
Feb 13 '20 #4
thanks for taking the time to explain.
May 6 '20 #5
AjayGohil
83 64KB
Hi,

In your program you use what as a function and also as a variable and in function declaration there is no parameter and in a function call you pass three parameter.so you have to add three parameter to function declaration.

Thank you
May 7 '20 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: BJ | last post by:
The application I have been developing is great except one flaw. When Windows NT shuts down, it doesn't send the Event to my application (if it did, it would close all of the open forms and kill an...
1
by: Nand Belani | last post by:
Hi, I have a MS Access 2000 database on the network, it is secured and the mdw file is on the network. The database works for most of the users on the network, but does not open for two of the...
1
by: VB Programmer | last post by:
I am setting up a intranet webserver that will run my ASP.NET website. (Everything works fine locally.) When I try accessing an aspx page, via IE, it gives me the "Page cannot be displayed" error,...
2
by: Chris Fink | last post by:
I encountered a very odd error this afternoon. A website that has been in production for quite some time suddenly came up with a page cannot be found on the main index.aspx page for the site. 5...
4
by: news.microsoft.com | last post by:
I need some help here guys.... i have been simply trying to delete a file from the webserver using asp.net using the following code. System.IO.File.Delete(FullPath); however the error message...
1
by: Abraham Andres Luna | last post by:
hello everyone, i have the basic authentication method selected for my iis settings. when i navigate to a url using the local computer the login succeeds and shows the web page correctly....
3
by: rajesh | last post by:
Hi, I have an ASP.net page that takes over an hour to execute. I get a Page Cannot Be Displayed error.after exactly 60 minutes. I have set the session timeout = 120 minutes. in both IIS...
0
by: sbhandary | last post by:
Hi, I have an ASP.net page that takes over an hour and sometimes more to execute. After the page has been running for 60 minutes, I get a Page Cannot Be Displayed error. I have set the session...
1
by: jdub33 | last post by:
I have a web project that used a vb6 class library. The asp page would call a createobject() to access the class library. I recently updated the vb6 class library to .net2005. I unregistered the...
3
by: dkyadav80 | last post by:
" "a" is assigned a value that is never used " getting error in C programming. pls any one solve this question. when and why becomes this type problem in turbo C/C++ compiler char a; FILE *f1;...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.