Thread: Problem with calling the function

  1. #1
    Registered User
    Join Date
    Oct 2018
    Posts
    7

    Problem with calling the function

    Code:
    #include <stdio.h>
    #include <math.h>
    int sum();
    double arcLength();
    double greatest(double t, double u, double v);
    int main() {
    	int result1, result2;
    	double s;
    	double highestnum;
    	result1 = Sum();
    	result2 = Sum();
    	s = arcLength();
    	highestnum = greatest(double t, double u, double v); // < keeps underlining double. 
    	printf("The highest number is %lf", highestnum);
    	printf("First sum = %d, Second sum = %d\n", result1, result2);
    	printf("Arclength = %lf meters", s);
    
    
    }
    int sum() {
    	int a, b, c;
    	printf("Enter a value for a: ");
    	scanf("%d", &a);
    	printf("Enter a value for b: ");
    	scanf("%d", &b);
    	printf("Enter a value for c: ");
    	scanf("%d", &c);
    	//printf("The sum of a, b, and c is: %d\n", a + b + c);
    	return a + b + c;
    }
    double arcLength() {
    	double r, AngleR, AngleD;
    	int choice;
    	printf("Input radius in meters for circle: ");
    	scanf("%lf", &r);
    	printf("Do you have an angle value in radians? (0 for yes or 1 for no): ");
    	scanf("%d", &choice);
    	if (choice > 0) {
    		printf("Enter an angle in degrees: ");
    		scanf("%lf", &AngleD);
    		printf("Your angle in radians is %lf\n", AngleD*0.017444);
    		printf("Input an angle in radians: ");
    		scanf("%lf", &AngleR);
    	}
    	else if (choice < 1) {
    		printf("Input an angle in radians: ");
    		scanf("%lf", &AngleR);
    	}
    	return r * AngleR;
    }
    double greatest(double t, double u, double v) {
    	printf("Enter 3 values: ");
    	scanf("%lf %lf %lf", &t, &u, &v);
    	if (t > u)
    		if (t > v)
    			return t;
    		else
    			return v;
    	else
    		if (u > v)
    			if (u > t)
    				return u;
    			else 
    				return v;
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    37,485
    > highestnum = greatest(double t, double u, double v); // < keeps underlining double.
    You don't include the types when you're calling a function.

    Look at your usage of printf on the next line, do you see types there?
    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.

  3. #3
    Registered User
    Join Date
    Oct 2018
    Posts
    7
    When I remove the double it just underlines the t u and v
    Quote Originally Posted by Salem View Post
    > highestnum = greatest(double t, double u, double v); // < keeps underlining double.
    You don't include the types when you're calling a function.

    Look at your usage of printf on the next line, do you see types there?

  4. #4
    Registered User
    Join Date
    Apr 2017
    Location
    Iran
    Posts
    92
    Hi,

    Consider this code :

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    double greater(double a, double b);
    double greatest(double a, double b, double c);
    
    int main(void)
    {
        double t;
        t = greatest(1.0,2.0,3.0);
    
        printf("%f\n",t);
        return EXIT_SUCCESS;
    }
    
    double greater(double a, double b)
    {
        double r;
        if (a>b)
            r=a;
        else 
            r=b;
        
        return r;
    }
    
    double greatest(double a, double b, double c)
    {
        double r;
        double ab = greater(a,b);
        
        r = greater(ab,c);
        
        return r;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 02-02-2016, 07:12 AM
  2. Problem with calling the function
    By XioNOverMazes in forum C++ Programming
    Replies: 1
    Last Post: 05-09-2015, 07:29 AM
  3. Function calling problem
    By johnnish in forum C Programming
    Replies: 5
    Last Post: 08-06-2009, 09:59 AM
  4. Problem calling a function
    By JOCAAN in forum C Programming
    Replies: 4
    Last Post: 11-01-2008, 12:17 PM
  5. Problem calling the function
    By HAssan in forum C Programming
    Replies: 6
    Last Post: 12-30-2005, 04:36 PM

Tags for this Thread