Connecting Tech Pros Worldwide Forums | Help | Site Map

how to combine this? help plz..

Newbie
 
Join Date: Oct 2009
Posts: 9
#1: Oct 9 '09
Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. #include<math.h>
  3.  
  4. int main(void)
  5. {
  6.     float x;
  7.     float k,result,sum;
  8.     float result2,sum1=0;
  9.     float x1;
  10.     int i,n;
  11.  
  12.     printf("Please enter a value of x:");
  13.     scanf("%f",&x);
  14.  
  15.   if(x>0&&x<=2)
  16.  
  17.     {result= sum+log10(x);
  18.     sum=0;
  19.  
  20.     printf("%f",result);}
  21.  
  22.  
  23.     else{
  24.     printf("Please enter a value that more than 0 and less or equall than 2.");
  25.     }
  26.  
  27.  return 0;
  28. }
  29.  
i want to insert this into above program because i want to print 2 different result..
how to do it? ive tried many times but it always error at the else.

Expand|Select|Wrap|Line Numbers
  1. x1 = (x - 1);
  2.  
  3. for( i = 1; i < n; i++)
  4. {
  5. k = ( (pow((x-1), (i+1)) )/ (i+1) );
  6. if( ((i+1) % 2) == 0)
  7. x1 -= k;
  8. else
  9. x1 += k;
  10.  
  11. result2=(sum1+x1)/2.303;
  12. }
  13.  
  14. printf("%f",result2);
  15.  

Banfa's Avatar
Administrator
 
Join Date: Feb 2006
Location: South West UK
Posts: 6,214
#2: Oct 9 '09

re: how to combine this? help plz..


Do you mean you get a compile error on that line? If so post the errors.
Expert
 
Join Date: Mar 2008
Location: Naperville, Illinois U.S.
Posts: 834
#3: Oct 9 '09

re: how to combine this? help plz..


I don't really understand what you're trying to insert or where you want to insert it. You say you get errors at the else; what are those errors?
myusernotyours's Avatar
Familiar Sight
 
Join Date: Nov 2007
Posts: 168
#4: Oct 9 '09

re: how to combine this? help plz..


Oh yes. And please do use code tags when you are posting code. It's so much more easier on the eyes.

Regards,

Alex.
Reply