Helping out a friend...

This is a discussion on Helping out a friend... within the C Programming forums, part of the General Programming Boards category; Originally Posted by rhymewithnothin Loko, you fixed it again. We're nearing the end, 5 more errors, and I may be ...

  1. #16
    Information Crocodile
    Join Date
    Dec 2004
    Posts
    204
    Quote Originally Posted by rhymewithnothin
    Loko, you fixed it again. We're nearing the end, 5 more errors, and I may be able to get some of them myself.

    Next one....

    "called object is not a function" referring to
    Code:
     areaTri = (1/2)(baseTri*heightTri);   //This is casting (baseTri*heightTri) to (1/2) which is obviously not correct  :D .
    
    this should be  areaTri = (1/2) * (baseTri*heightTri);   thats if your trying to multiply 1/2 with the product of  baseTri*heightTri).
    This would be my last reply i gtg somewhere.

    peace

  2. #17
    cwr
    cwr is offline
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    869
    Quote Originally Posted by jcarouth
    Code:
    areaTri = (double)(1/2)*(baseTri*heightTri);
    I didn't read where you declared areaTri, but I assumed it is of type double.
    That still won't make 1/2 evaluate to 0.5. See my above post.

  3. #18
    Registered User
    Join Date
    Sep 2005
    Posts
    12
    Thank you very much. When I compile and link now all the error messages are gone. Thanks again. I'll check back if I need more help.

  4. #19
    Registered User
    Join Date
    Sep 2005
    Posts
    12
    OK all the erros are gone, but when I try to run the I/O, it will ask me what shape I want to find the area of, and when I type what I want, it just ends the program. Here is the completed code if someone wants to put it in their compiler and try to figure it out...

    Code:
    /*This program will compute the area of a rectangle,                        */
    /*triangle, circle, ellipse, and sphere.                                    */
    
    #include <stdio.h>
    #include <math.h>
    #define PI 3.141593
    
    int main(void)
    {
       /* Declare first variable. */
    	
    	char shape, rectangle, triangle, circle, ellipse, sphere;
    	 	 	
    	/* Determine which shape to find the area of */
      
       printf("Find the area of a rectangle, triangle, circle, ellipse, or sphere?");
    	scanf("%c",&shape);
    	
    	if (shape == rectangle){	   
    		/* Declare set of variables for this shape */
    		
    		float lengthRect, widthRect, areaRect;
    		       printf("Enter the length. \n");
    				 scanf("%lf",&lengthRect);
    				 printf("Enter the width. \n");
    				 scanf("%lf",&widthRect);
    		      
    				 /* Compute the area */
    		  
    		       areaRect = (lengthRect*widthRect);
    				 printf("The area of the rectangle is "
    				        "%5.2lf \n",areaRect);
    	}
    	else if (shape == triangle){
    		   /* Declare set of variables for this shape */
    	
    			float baseTri, heightTri, areaTri;
    			       printf("Enter the base. \n");
    					 scanf("%lf",&baseTri);
    					 printf("Enter the height. \n");
    					 scanf("%lf",&heightTri);
    	
    					 /* Compute the area */
    	
    					 areaTri = (.5)*(baseTri*heightTri);
    					 printf("The area of the triangle is "
    					        "%5.2lf \n",areaTri);
    	}				  
    	else if (shape == circle){
    		   /* Declare set of variables for this shape */
    	
    			float radiusCirc, areaCirc;
    			       printf("Enter the radius. \n");
    					 scanf("%lf",&radiusCirc);
    	
    					 /* Compute the area */
    	
    					 areaCirc = PI*(radiusCirc*radiusCirc);
    					 printf("The area of the circle is "
    					        "%5.2lf \n",areaCirc);
       }
    	else if (shape == ellipse){
    		   /* Declare set of variables for this shape */
    		
             float semiaxisA, semiaxisB, areaEllipse;
    			              printf("Enter the length of semiaxisA. \n");
    					 		  scanf("%lf",&semiaxisA);
    					        printf("Enter the length of semiaxisB. \n");
    					        scanf("%lf",&semiaxisB);
    					       
    							  /* Compute the area */
    							  
    					        areaEllipse = (PI*semiaxisA*semiaxisB);
    					        printf("The area of the ellipse is "
    					        "%5.2lf \n",areaEllipse);
      }
      else if (shape == sphere){
    		 /* Declare set of variables for this shape */
    							
    		 float radiusSphere, areaSphere;
    							       printf("Enter the length of the radius. \n");
    									 scanf("%lf",&radiusSphere);
    									 
    									 /* Compute the area */
    									 
    									 areaSphere = (4*PI*radiusSphere*radiusSphere);
    									 printf("The surface area of the sphere is "
    									        "%5.2lf \n",areaSphere);
      }			
    	    return 0;
    }
    Thanks again.

  5. #20
    Registered User
    Join Date
    Sep 2005
    Posts
    20
    Quote Originally Posted by cwr
    That still won't make 1/2 evaluate to 0.5. See my above post.

    meant to be ((double)(1)/2)....sorry

  6. #21
    Registered User
    Join Date
    Sep 2005
    Posts
    20
    Code:
    /*This program will compute the area of a rectangle,                        */
    /*triangle, circle, ellipse, and sphere.                                    */
    
    #include <stdio.h>
    #include <math.h>
    #define PI 3.141593
    
    int main(void)
    {
       /* Declare first variable. */
    	
    	char shape;
    	//char shape, rectangle, triangle, circle, ellipse, sphere;
    	 	 	
    	/* Determine which shape to find the area of */
      
       printf("Find the area of a rectangle, triangle, circle, ellipse, or sphere?");
    	scanf("%c",&shape);
    	
    	if (shape == 'r'){	   
    		/* Declare set of variables for this shape */
    		
    		float lengthRect, widthRect, areaRect;
    		       printf("Enter the length. \n");
    				 scanf("%lf",&lengthRect);
    				 printf("Enter the width. \n");
    				 scanf("%lf",&widthRect);
    		      
    				 /* Compute the area */
    		  
    		       areaRect = (lengthRect*widthRect);
    				 printf("The area of the rectangle is "
    				        "%5.2lf \n",areaRect);
    	}
    	else if (shape == 't'){
    		   /* Declare set of variables for this shape */
    	
    			float baseTri, heightTri, areaTri;
    			       printf("Enter the base. \n");
    					 scanf("%lf",&baseTri);
    					 printf("Enter the height. \n");
    					 scanf("%lf",&heightTri);
    	
    					 /* Compute the area */
    	
    					 areaTri = (.5)*(baseTri*heightTri);
    					 printf("The area of the triangle is "
    					        "%5.2lf \n",areaTri);
    	}				  
    	else if (shape == 'c'){
    		   /* Declare set of variables for this shape */
    	
    			float radiusCirc, areaCirc;
    			       printf("Enter the radius. \n");
    					 scanf("%lf",&radiusCirc);
    	
    					 /* Compute the area */
    	
    					 areaCirc = PI*(radiusCirc*radiusCirc);
    					 printf("The area of the circle is "
    					        "%5.2lf \n",areaCirc);
       }
    	else if (shape == 'e'){
    		   /* Declare set of variables for this shape */
    		
             float semiaxisA, semiaxisB, areaEllipse;
    			              printf("Enter the length of semiaxisA. \n");
    					 		  scanf("%lf",&semiaxisA);
    					        printf("Enter the length of semiaxisB. \n");
    					        scanf("%lf",&semiaxisB);
    					       
    							  /* Compute the area */
    							  
    					        areaEllipse = (PI*semiaxisA*semiaxisB);
    					        printf("The area of the ellipse is "
    					        "%5.2lf \n",areaEllipse);
      }
      else if (shape == 's'){
    		 /* Declare set of variables for this shape */
    							
    		 float radiusSphere, areaSphere;
    							       printf("Enter the length of the radius. \n");
    									 scanf("%lf",&radiusSphere);
    									 
    									 /* Compute the area */
    									 
    									 areaSphere = (4*PI*radiusSphere*radiusSphere);
    									 printf("The surface area of the sphere is "
    									        "%5.2lf \n",areaSphere);
      }			
    	    return 0;
    }
    I changed all the comparisons to characters since you are comparing against a character.

    The user needs to enter an r for rectangle, t for triangle, et cetera. There are ways to implement using the entire word, ie rectangle. It runs right now. I only tested that it will accept r for rectangle, and it appears that you need to check your computational algorithm as it gave me an area of 0.00 for a 2 by 3 rectangle.

  7. #22
    Registered User
    Join Date
    Sep 2005
    Posts
    12
    Can do. I'll see what I can do. Thanks.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Friend cannot inherit from private subclass
    By MWAAAHAAA in forum C++ Programming
    Replies: 4
    Last Post: 11-19-2006, 04:44 PM
  2. arithmetic operator friend functions
    By linucksrox in forum C++ Programming
    Replies: 7
    Last Post: 02-06-2006, 11:39 PM
  3. Problem with friend functions in templated linked list
    By Strait in forum C++ Programming
    Replies: 2
    Last Post: 03-13-2005, 04:24 PM
  4. friend function and friend classes...usage question??
    By actionbasti in forum C++ Programming
    Replies: 2
    Last Post: 10-30-2003, 10:53 PM
  5. Quack! It doesn't work! >.<
    By *Michelle* in forum C++ Programming
    Replies: 8
    Last Post: 03-02-2003, 12:26 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21