Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,560 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,898 people online right now. Registration is fast and FREE... Join Now!




error: called object is not a function

 
Reply to this topicStart new topic

error: called object is not a function

lwlewis
16 May, 2008 - 11:14 PM
Post #1

New D.I.C Head
*

Joined: 15 Feb, 2008
Posts: 5

I am trying to write a C program that will first fill an array with upto 20 integers and then finds both the subscript of the largest item and the value of the largest item.

I am getting a couple of errors that I do not quit understand. I am using netbeans and cygwin as my compiler.


Here is the code I have so far.

CODE

#include <stdio.h>
#include <math.h>

#define item 20
int
main(void)

   {
   int arr[item];
   int i;
   int cur_large;
   int large_sub;

   printf ("Enter %d numbers separated by blanks or <return>s\n", item);
  
   for (i = 0; i < item; ++1)
       scanf("%d", arr[i]);
  
cur_large = arr[0];
    for (i = 0; i < arr[item]; ++i)
        if (arr[i] > cur_large)
            cur_large = arr(i);
    return(cur_large);

  

large_sub = 0;
    
    for (i = 0; i < arr[item]; ++i)
        if (arr[i] < arr[large_sub])
            large_sub = i;
      return(large_sub);

return(0);
}


Here is what the debugger tells me

CODE

Running "C:\cygwin\bin\make.exe  -f Makefile CONF=Debug" in E:\Course Technology\CS 263\Assignment_4_1

/usr/bin/make -f nbproject/Makefile-Debug.mk SUBPROJECTS= .build-conf
make[1]: Entering directory `/cygdrive/e/Course Technology/CS 263/Assignment_4_1'
mkdir -p build/Debug/Cygwin-Windows
gcc.exe    -c -g -o build/Debug/Cygwin-Windows/Arr.o Arr.c
Arr.c: In function `main':
Arr.c:16: error: invalid lvalue in increment
Arr.c:22: error: called object is not a function
make[1]: *** [build/Debug/Cygwin-Windows/Arr.o] Error 1
make[1]: Leaving directory `/cygdrive/e/Course Technology/CS 263/Assignment_4_1'
make: *** [.build-impl] Error 2

Build failed. Exit value 2.


any help or advice would be appreciated.
User is offlineProfile CardPM
+Quote Post

skaoth
RE: Error: Called Object Is Not A Function
16 May, 2008 - 11:20 PM
Post #2

D.I.C Regular
Group Icon

Joined: 7 Nov, 2007
Posts: 343



Thanked: 10 times
Dream Kudos: 100
My Contributions
A quick glance points to this line
cur_large = arr(i);
maybe it should be cur_large = arr[i]??
User is online!Profile CardPM
+Quote Post

skater_00
RE: Error: Called Object Is Not A Function
17 May, 2008 - 02:03 PM
Post #3

D.I.C Head
Group Icon

Joined: 30 Apr, 2008
Posts: 173



Thanked: 4 times
Dream Kudos: 50
My Contributions
Code edited and compiles. (This is C++ now though, no big deal.) However, the program still crashes as soon as you enter the first number. Still figuring out...

cpp

#include <cstdio>
#include <cmath>
#include <iostream>

using namespace std;

#define item 20

int main()
{
int arr[item], i, cur_large, large_sub;

cout << "Enter " << item << " numbers separated by blanks or return/s: " << endl << endl;

for (i = 0; i < item; ++i) // *** Your increment was "++1", should be "++i". ***
cin >> arr[item];

cur_large = arr[0];

for (i = 0; i < arr[item]; ++i)
if (arr[i] > cur_large)
cur_large = arr[i]; // *** Your array index was between brackets, not []'s. ***

return cur_large;

large_sub = 0;

for (i = 0; i < arr[item]; ++i)
if (arr[i] < arr[large_sub])
large_sub = i;

return large_sub;

return 0;
}


This post has been edited by skater_00: 17 May, 2008 - 02:26 PM
User is offlineProfile CardPM
+Quote Post

gabehabe
RE: Error: Called Object Is Not A Function
18 May, 2008 - 06:47 AM
Post #4

Donkey DIC
Group Icon

Joined: 6 Feb, 2008
Posts: 5,539



Thanked: 98 times
Dream Kudos: 2650
Expert In: ruling the world.

My Contributions
Your problem is this line:
cin >> arr[item];
You're trying to input arr[20] 20 times, instead of using your index i
It should look like this: cin >> arr[i];

Hope this helps smile.gif
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/2/08 11:31PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month