C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 3rd, 2012, 04:53 AM
Giorgos Giorgos is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2012
Posts: 24 Giorgos User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 27 m 36 sec
Reputation Power: 0
Ignore a particular element?

Hello,
i have a small problem in this function code.I want when the IN[n]+1 become bigger than 4 to ignore in this particular n the P[n].VALUE and P[n].LINE.
Can you help me?

Code:
int compair_value()
{
	int min,i,c,j;
		for(n=0;n<4;n++){
			IN[n]=0;
		}
		
for(c=0;c<20;c++){
	for(n=0;n<4;n++){
		IN[n]=P[n].LINE;
		P[n].VALUE=A[n][IN[n]];
		}

		min=P[0].VALUE;
		for(j=0;j<4;j++){
		if(min>P[j].VALUE)
			{
			min=P[j].VALUE;	
			}}
			for(n=0;n<4;n++){
			if(min==P[n].VALUE){
				P[n].LINE=IN[n]+1;
				B[c]=P[n].VALUE;	
				
			}}
			
			}
			
}

Reply With Quote
  #2  
Old December 3rd, 2012, 05:02 AM
salem's Avatar
salem salem is offline
Contributed User
Click here for more information
 
Join Date: Jun 2005
Posts: 3,840 salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)  Folding Points: 153 Folding Title: Novice Folder
Time spent in forums: 2 Months 3 Weeks 2 Days 21 h 15 m 20 sec
Reputation Power: 1774
It would help if you could indent code.
Code:
int compair_value()
{
  int min, i, c, j;
  for (n = 0; n < 4; n++) {
    IN[n] = 0;
  }

  for (c = 0; c < 20; c++) {
    for (n = 0; n < 4; n++) {
      IN[n] = P[n].LINE;
      P[n].VALUE = A[n][IN[n]];
    }
    min = P[0].VALUE;
    for (j = 0; j < 4; j++) {
      if (min > P[j].VALUE) {
        min = P[j].VALUE;
      }
    }
    for (n = 0; n < 4; n++) {
      if (min == P[n].VALUE) {
        P[n].LINE = IN[n] + 1;
        B[c] = P[n].VALUE;
      }
    }
  }
}


> I want when the IN[n]+1 become bigger than 4
So how about
Code:
if ( IN[n]+1 <= 4 ) {
   // do stuff
}
__________________
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper

Reply With Quote
  #3  
Old December 3rd, 2012, 05:16 AM
Giorgos Giorgos is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2012
Posts: 24 Giorgos User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 27 m 36 sec
Reputation Power: 0
thank you for the quick answer but IN[n]<=4 do what??

Reply With Quote
  #4  
Old December 3rd, 2012, 05:39 AM
salem's Avatar
salem salem is offline
Contributed User
Click here for more information
 
Join Date: Jun 2005
Posts: 3,840 salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)  Folding Points: 153 Folding Title: Novice Folder
Time spent in forums: 2 Months 3 Weeks 2 Days 21 h 15 m 20 sec
Reputation Power: 1774
> thank you for the quick answer but IN[n]<=4 do what??
If you're asking that, how did you manage to write all that code to begin with!?

Reply With Quote
  #5  
Old December 3rd, 2012, 06:22 AM
Giorgos Giorgos is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2012
Posts: 24 Giorgos User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 27 m 36 sec
Reputation Power: 0
Your answer is very general and wrong!

Reply With Quote
  #6  
Old December 3rd, 2012, 06:37 AM
salem's Avatar
salem salem is offline
Contributed User
Click here for more information
 
Join Date: Jun 2005
Posts: 3,840 salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)  Folding Points: 153 Folding Title: Novice Folder
Time spent in forums: 2 Months 3 Weeks 2 Days 21 h 15 m 20 sec
Reputation Power: 1774
Well I guess that's a function of your vague and ill-defined question.

We can't compile it, because you don't declare IN, or what the structure behind it is.
We can't run it, because there is no data.

Your vaguest of questions can only be interpreted as "how do I do an if statement". If you're still stuck, then read your C book.

Then swing by here before asking another question

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Ignore a particular element?

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap