Thread: calculating percentage value in c

  1. #1
    Registered User
    Join Date
    Feb 2015
    Posts
    13

    calculating percentage value in c

    Dear all,

    I am looking for sample code to calculate percentage. i have variable nominal current, overload current ,

    this value should be in steps . how it can be done in C

    Nominal current and overload_trip_current_limit are unsigned int variable

    if nominal current > ((overload_trip_current_limit *30%)+overload_trip_current_lmit ) then trip time should be low

    if nominal current > ((overload_trip_current_limit *1%)+overload_trip_current_limit ) then trip time should be high

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Recall that x% of some quantity means x/100.0 of that quantity.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Feb 2015
    Posts
    13
    is it correct
    OL_Point=Setvalue of current =30(unsigned int)
    UC_point =set time=30(unsigned int)
    Rph_Current,Yph_Current,Bph_Current are actual running current (Decalred as unsigned int)
    OL_curve=1=20% of OL_point
    OL_curve=1=50% of OL_point
    OL_curve=1=100% of OL_point

    Code:
    
                           if(((Rph_Current>OL_Point)||(Yph_Current>OL_Point)||(Bph_Current>OL_Point)))
                             {
                                if(OL_Curve==1)
                                {
                                 Percenatge_Calculated= ((int)(OL_Point*percentage2C_Limit)+OL_Point);
                                 if((Rph_Current>Percenatge_Calculated)||(Yph_Current>Percenatge_Calculated)||(Bph_Current>Percenatge_Calculated))
                                  {
                                        percentage2C_Limit=percentage2C_Limit-1;
                                        Counter_OCRT--;
                                        
                                        if(Counter_OCRT<=0)
                                        {
                                        Counter_OCRT=UC_Point;
                                        OverLoad_Flag=1;                        
                                           Hold = 0;             
                                        Hold_control=0;    
                                        }else
                                     if(percentage2C_Limit==1)
                                       {
                                        percentage2C_Limit=20;    
                                       }    
                                     
                                                                       
                                  }
                                  else
                                    {
                                       Counter_OCRT=UC_Point;
                                       OverLoad_Flag=0; 
                                       Rph_OLFlag=0;
                                       Yph_OLFlag=0;
                                       Bph_OLFlag=0; 
                                        
                                        
                                     }            
                                   } 
                                
                                
                                if(OL_Curve==2)
                                {
                                 Percenatge_Calculated= ((int)(OL_Point*percentage5C_Limit)+OL_Point);
                                 if((Rph_Current>Percenatge_Calculated)||(Yph_Current>Percenatge_Calculated)||(Bph_Current>Percenatge_Calculated))
                                  {
                                        percentage5C_Limit=percentage5C_Limit-1;                                    
                                        Counter_OCRT--;
                                        
                                        if(Counter_OCRT<=0)
                                        {
                                        Counter_OCRT=UC_Point;
                                        OverLoad_Flag=1;                        
                                           Hold = 0;             
                                        Hold_control=0;    
                                        }else
                                       if(percentage5C_Limit==1)
                                       {
                                        percentage5C_Limit=50;    
                                       }   
                                                                       
                                  }
                                  else
                                    {
                                       Counter_OCRT=UC_Point;
                                       OverLoad_Flag=0; 
                                       Rph_OLFlag=0;
                                       Yph_OLFlag=0;
                                       Bph_OLFlag=0; 
                                        
                                        
                                     }            
                                    
                                }
                                
                                
                                if(OL_Curve==2)
                                {
                                 Percenatge_Calculated= ((int)(OL_Point*percentage10C_Limit)+OL_Point);
                                 if((Rph_Current>Percenatge_Calculated)||(Yph_Current>Percenatge_Calculated)||(Bph_Current>Percenatge_Calculated))
                                  {
                                        percentage10C_Limit=percentage10C_Limit-1;                                    
                                        Counter_OCRT--;
                                        
                                        if(Counter_OCRT<=0)
                                        {
                                        Counter_OCRT=UC_Point;
                                        OverLoad_Flag=1;                        
                                           Hold = 0;             
                                        Hold_control=0;    
                                        }else
                                       if(percentage10C_Limit==1)
                                       {
                                        percentage10C_Limit=100;    
                                       }   
                                                                       
                                  }
                                  else
                                    {
                                       Counter_OCRT=UC_Point;
                                       OverLoad_Flag=0; 
                                       Rph_OLFlag=0;
                                       Yph_OLFlag=0;
                                       Bph_OLFlag=0; 
                                        
                                        
                                     }             
                                    
                                }
                                 
                                
                             }
                              else
                            {   
                                   Counter_OCRT=UC_Point;
                                   OverLoad_Flag = 0; 
                                   Rph_OLFlag=0;
                                   Bph_OLFlag=0;
                                   Yph_OLFlag=0;          
                            }
    Last edited by ajitnayak87; 01-18-2019 at 10:37 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 05-10-2015, 06:57 AM
  2. percentage question
    By Naygath in forum C Programming
    Replies: 16
    Last Post: 02-09-2011, 12:42 PM
  3. Help with a percentage
    By Alecroy in forum C++ Programming
    Replies: 3
    Last Post: 09-24-2010, 07:24 PM
  4. Calculating a percentage
    By swgh in forum C++ Programming
    Replies: 3
    Last Post: 11-24-2006, 10:24 AM
  5. Percentage
    By skyglin in forum C Programming
    Replies: 7
    Last Post: 06-23-2003, 05:18 PM

Tags for this Thread