Thread: How do I fix these Errors??

  1. #1
    Registered User Maiq's Avatar
    Join Date
    Aug 2002
    Posts
    10

    How do I fix these Errors??

    Hello everyone. I've been trying to figure out how to fix these errors for about two hours now and I have yet to figure out how. Here are the errors I get:
    http://www.carbongraphx.com/errors.jpg
    Here's my program:
    Code:
    //fun.cpp
    //Jason Smith
    /*This program converts Celsius to Fahrenheit values, finds volume of a given
      sphere, and the hypotenuse of a given right triangle*/
    
    #include <iostream.h>
    #include <iomanip.h>
    #include <math.h>
    
    
    const float PI = 3.14159;
    double ctoF(double celsius);
    double volume(double radius);
    double hypotenuse(double firstleg, double secondleg, double c);
    double ftoC(double fahr);
    void intro();
    
    int main()
    {
    	double celsius, fahr, radius, firstleg, secondleg;
    	intro();
    	cout <<"Enter a Celsius temperature to be converted to Fahrenheit: ";
    	cin >>celsius;
    	cout <<endl;
    	cout <<"Enter a Fahrenheit temperature to be converted to Celsius: ";
    	cin >>fahr;
    	cout <<endl;
    	cout <<"Enter the radius of the sphere: ";
    	cin >>radius;
    	cout <<endl;
    	cout <<"Enter the legs of the right triangle with a space between them: ";
    	cin >>firstleg >>secondleg;
    	cout << setiosflags(ios::right|ios::fixed|ios::showpoint);
    	cout << setprecision(2);
    	cout << celsius <<" degress C = " << ctoF(celsius) <<" degrees F."<<endl;
    	cout << fahr <<" degrees F = " << ftoC(fahr) <<" degrees C."<<endl;
    	cout <<"The volume of a sphere of radius "<<radius<<" is "<< volume(radius) <<".";
    	cout <<"The hypotenuse of a right triangle of legs "<< firstleg <<" and "<< secondleg
    	     <<" is "<< hypotenuse(firstleg, secondleg) <<".";		
    }
    
    void intro()
    {
    	cout << "Program: Fun.CPP";
    	cout << "By Jason Smith on October 20, 2002";
    	cout <<endl;
    	cout << "**This program converts Celsius to Fahrenheit values,\n";
    	cout << "finds the volume of a given sphere, and the hypotenuse \n";
    	cout << "of a given right triangle.\n";
    	cout << "***LET THE FUN COMMENCE!!***";
    	cout <<endl;
    	cout <<endl;
    }
    
    double ctoF(double celsius)
    {
    	return ((1.8*celsius) + 32);
    }
    
    double ftoC(double fahr)
    {
    	return (5/9 * (fahr - 32));
    }
    
    double volume(double radius)
    {
    	return (4/3*(PI * (double pow(double radius, double 3)));
    }
    
    double hypotenuse(double firstleg, double secondleg, double c)
    {
    	c = (double pow(double firstleg, double 2)) + (double pow(double secondleg, double 2));
    	return (double sqrt(double c));
    }
    Any help would be greatly appreciated. Thanks.
    Jason


    Code tags added by kermi3

  2. #2
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    really, the error message is in basic english. you define a function hypotnuse() which takes three double args, and then you try to call it with only two.

    now of course you're program has other errors as well, but dont sit there and tell me you couldn't figure that one out.
    hello, internet!

  3. #3
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    By the way, quote tags are no replacement for code tags. Also here is a helpful tip. You can do this:

    Code:
    double hypotenuse(double firstleg, double secondleg, double c = 1.0)
    {
        c = (double pow(double firstleg, double 2)) + (double pow(double secondleg, double 2));
        return (double sqrt(double c));
    }
    [edit]
    Almost forgot. When you set "default" values like this you mush also prototype them with the default value. Actually, once prototyped with a default value I don't think you need the default value in the function declaration.

    example prototype:
    Code:
    double hypotenuse(double,double,double=1.0);
    [/edit]
    Last edited by master5001; 10-20-2002 at 07:04 PM.

  4. #4
    Just a Member ammar's Avatar
    Join Date
    Jun 2002
    Posts
    953
    You have many problems in your program...
    For example:
    in addition to what moi said...
    You should return a value in the main()...
    What do you mean by this:
    return (double sqrt(double c));
    double pow(double secondleg, double 2)
    ???
    I don't get it, what are you trying to do?

  5. #5
    Registered User Maiq's Avatar
    Join Date
    Aug 2002
    Posts
    10
    thanks everyone for your help.
    ammar:
    the 'pow' function is the power function, which takes double x to the power of double y ex: double pow(double x, double y) but i can see that, yes, i messed up the order there.

    thanks everyone.

  6. #6
    Registered User
    Join Date
    Oct 2002
    Posts
    10

    Wink

    I thought i'll comment on this:

    Code:
    double ftoC(double fahr)
    {
    return (5/9 * (fahr - 32));
    }
    This won't work unless you put 5.0/9.0, it is looking for double type, but all it sees are int, so it'll skip them.

    Val

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Ten Errors
    By AverageSoftware in forum Contests Board
    Replies: 0
    Last Post: 07-20-2007, 10:50 AM
  2. Strange/false errors
    By Ganoosh in forum Windows Programming
    Replies: 8
    Last Post: 10-20-2005, 04:54 PM
  3. strange errors?
    By egomaster69 in forum C Programming
    Replies: 6
    Last Post: 12-21-2004, 06:13 PM
  4. Help me with these errors... :-(
    By major_small in forum C++ Programming
    Replies: 6
    Last Post: 09-07-2003, 08:18 PM
  5. Errors when including winsock2.h
    By skiingwiz in forum Windows Programming
    Replies: 2
    Last Post: 12-27-2002, 07:32 PM