GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 27-Nov-2005, 15:12
warborules warborules is offline
New Member
 
Join Date: Nov 2005
Posts: 6
warborules is on a distinguished road

subscript error in coding


here are the circumstances:
  • i have declared the array and the function at the start of the program.
  • i have declared values for y[i], c, m and x[i]
  • the equation im trying to achieve is the total sum of (y[i]-c-m(x[i]))^2 for each value of i
  • the error in salford plato, in c, says "error 116 - Subscript applied to the wrong type of object"
  • here is the part of the program that matters:
at the declaration point:

CPP / C++ / C Code:
int N, i;

float x[MAX], y[MAX], xsqrd[MAX], txs, sumx, sumx2, D, Exy, Exy2[MAX], Ex, Ey, 
m, c, o2y, o2y3;

void input (float numbers []);
void totxsqrd (float numbers []);
void sumx3 (float numbers []);
void calcD (float numbers []);
void Exy3 (float numbers []);
void Ex2 (float numbers []);
void Ey2 (float numbers []);
void m2 (float numbers []);
void c2 (float numbers []);
void o2y2 (float numbers []);

int main()

{
  float numbers [150];
  input (numbers);
  totxsqrd (numbers);
  sumx3 (numbers);
  calcD (numbers);
  Exy3 (numbers);
  Ex2 (numbers);
   Ey2 (numbers);
      m2 (numbers);
      c2 (numbers);
      o2y2 (numbers);
}

and at the bottom of the program where i am working:

CPP / C++ / C Code:
void o2y2 (float numbers []) /* */
{
  o2y3=((y[i]-c-(m*x[i]))*(y[i]-c-(m*x[i])));
  o2y=0;
  for (i=0; i<=N-1; i++)
  o2y=o2y+o2y3[i];
  printf("\nThe sum of (y-c-mx) all squared is %f\n", o2y);
}

help me, you are cleverer than me!!
Last edited by LuciWiz : 28-Nov-2005 at 04:31. Reason: Please insert your C code between [c] & [/c] tags
  #2  
Old 27-Nov-2005, 15:13
warborules warborules is offline
New Member
 
Join Date: Nov 2005
Posts: 6
warborules is on a distinguished road

Re: subscript error in coding


basically, where have i gone wrong, there is only one error aparently
  #3  
Old 27-Nov-2005, 15:15
warborules warborules is offline
New Member
 
Join Date: Nov 2005
Posts: 6
warborules is on a distinguished road

Re: subscript error in coding


oh and the error is in the line which says:

"o2y=o2y+o2y3[i];"
  #4  
Old 27-Nov-2005, 16:03
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,335
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all

Re: subscript error in coding


Please Read the Guidelines

Quote:
Originally Posted by warborules
oh and the error is in the line which says:

"o2y=o2y+o2y3[i];"
o2y3 is not an array....

CPP / C++ / C Code:
float x[MAX], y[MAX], xsqrd[MAX], txs, sumx, sumx2, D, Exy, Exy2[MAX], Ex, Ey, m, c, o2y, o2y3;
Please split your line -- it's too long. Convention is generally around 80 characters but on a forum that value should be shortened some...
__________________

During the election they said Obama could only be elected when pigs fly. Well, we currently have an epidemic of Swine Flu. Coincidence?
  #5  
Old 27-Nov-2005, 16:28
warborules warborules is offline
New Member
 
Join Date: Nov 2005
Posts: 6
warborules is on a distinguished road

Re: subscript error in coding


could you help me in what to change the coding to? sorry about writing too longer lines-didnt realise
  #6  
Old 27-Nov-2005, 16:50
kobi_hikri's Avatar
kobi_hikri kobi_hikri is offline
Regular Member
 
Join Date: Apr 2005
Location: Israel
Posts: 431
kobi_hikri has a spectacular aura aboutkobi_hikri has a spectacular aura about

Re: subscript error in coding


Quote:
Originally Posted by warborules
help me, you are cleverer than me!!

No, we are not. Don't underestimate yourself

As Walt noticed, you are referring to an element of the array o2y3 at index i - but o2y3 is float and not an array of any type.
Another thing I noticed is that you declared main as int but never return anything. I think it would be better to return the value you promised to return .

Quote:
Originally Posted by warborules
could you help me in what to change the coding to?

Explain your function's purpose, and supply complete code.

Kobi.
__________________
It's actually a one time thing (it just happens alot).
  #7  
Old 27-Nov-2005, 18:16
Paramesh's Avatar
Paramesh Paramesh is offline
Regular Member
 
Join Date: Sep 2005
Location: The Milky Way
Posts: 929
Paramesh is a jewel in the roughParamesh is a jewel in the roughParamesh is a jewel in the rough

Re: subscript error in coding


Hi warborules,

In this line:
CPP / C++ / C Code:
o2y3=((y[i]-c-(m*x[i]))*(y[i]-c-(m*x[i])));  /* what is the purpose ?? */
  o2y=0;

for (i=0; i<=N-1; i++)
  o2y=o2y+o2y3[i];         /* o2y3 is not an array. that line should be here... */

  printf("\nThe sum of (y-c-mx) all squared is %f\n", o2y);

The line in which you are calculating o2y3 should come inside the for loop.
For example, like this:
CPP / C++ / C Code:
  for (i=0; i<=N-1; i++)
  {
    o2y3=( ( (y[i]-c- (m*x[i]) ) * ( (y[i]-c- (m*x[i]) ) );
    o2y=o2y+o2y3;
  }

Regards,
Paramesh.
__________________

Don't walk in front of me, I may not follow.
Don't walk behind me, I may not lead.
Just walk beside me and be my friend.
 
 

Recent GIDBlogToyota - 2009 May Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
i really need help in coding this applet.. i gave up !! plz help 123awd Java Forum 7 02-Nov-2005 04:33
PHP/MySQL coding issue cmarti MySQL / PHP Forum 3 26-Jul-2004 09:01
Pls help in this coding. harsha C++ Forum 5 08-Apr-2004 21:48
Using an array and finding the element number (subscript) tommy69 C Programming Language 27 05-Apr-2004 13:23
coding a word with a givin factor funnyf C++ Forum 2 13-Jan-2004 09:32

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 23:37.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.