Results 1 to 9 of 9

Thread: My simple cheat my homework prog. :) but it dont work.

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2000
    Location
    New Hampshire
    Posts
    32

    Talking

    OK today i desided no more hard math work and i made a program to increase my efficiancy.
    calling a function that does stuff aint that easy like vb. please tell me what im forgetting.

    Code:
    
    #include <stdio.h>
    #include <iostream.h>
    
    const double Pi = 3.141592654;
    char choice;
    
    int main()
    {
    	printf("a.	Cylinder\n");
    	printf("b.	Cone\n");
    	printf("c.	Prism\n");
    	printf("d.	Pyramid\n");
    	printf("--------------\n");
    	printf("x.	Exit\n");
    
    	cin>>choice;
    
    	switch ( choice ){
    	case 'a':
    		  LaSaCylinder();
    		  break;
    	case 'x':
    		return 0;
    	};
    
    };
    //////////////////////////
    //Cylinder Calculation ///
    //////////////////////////
    //LA = Lateral Area    ///
    //////////////////////////
    //SA = Surface Area    ///
    //////////////////////////
    void LaSaCylinder(int radius, int hieght, double LA, double SA);
    { 
    	cout << "What is the radius of the base?\n";
    	cin >> radius;
    	cout << "What is the height of the Cylinder?\n";
    	cin >> height;
    
    	LA = (2 * Pi * radius) * height;
    	SA = LA + (2 * (Pi * (radius^2)));
    
    	cout << LA << " is the Lateral area.\n";
    	cout << SA << " is the Surface area.\n";
    };
    this has been more work than i thought! m8's! Heres my craptacular error!
    |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ||||||||||||||
    --------------------Configuration: Math - Win32 Debug--------------------
    Compiling...
    Math.cpp
    D:\Ftp\BIN\Math\Math.cpp(21) : error C2065: 'LaSaCylinder' : undeclared identifier
    D:\Ftp\BIN\Math\Math.cpp(35) : error C2373: 'LaSaCylinder' : redefinition; different type modifiers
    D:\Ftp\BIN\Math\Math.cpp(36) : error C2447: missing function header (old-style formal list?)
    Error executing cl.exe.

    Math.exe - 3 error(s), 0 warning(s)
    ---------------------------------------------------------------------------------------

    it just Got worse!
    Last edited by factor777; Feb 13th, 2001 at 08:40 PM.

  2. #2
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    You don't include the return type when you're calling a function, otherwise it's a function declaration. I see people do this a lot, it must be confusing

    Code:
    	switch ( choice ){
    	case 'a':
    		  LaSaCylinder();
    		  break;
    	case 'x':
    		return 0;
    	};
    Something like that will do it.
    Harry.

    "From one thing, know ten thousand things."

  3. #3
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    Incidentally, in case you hadn't noticed, that's just the same as in VB
    Harry.

    "From one thing, know ten thousand things."

  4. #4

    Thread Starter
    Member
    Join Date
    Sep 2000
    Location
    New Hampshire
    Posts
    32
    ok its still guaking at me, i dont know what it wants.

    i have been fixing repetitive things like this for an hour! it sucks.

    oh well i need the experiance right? (i'll answer that) Right!

  5. #5
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Bethel, North Carolina, USA
    Posts
    987
    Forgive me if my technical grammar is not up to par in C++ but don't you have to have a function declaration if the function is written after the main() function, i.e.

    Code:
    #include <stdio.h>
    #include <iostream.h>
    
    const double Pi = 3.141592654;
    char choice;
    
    void LaSaCylinder(int radius, int hieght, double LA, double SA);
    
    int main()
    {
    	printf("a.	Cylinder\n");
    	printf("b.	Cone\n");
    	printf("c.	Prism\n");
    	printf("d.	Pyramid\n");
    	printf("--------------\n");
    	printf("x.	Exit\n");
    
    	cin>>choice;
    
    	switch ( choice ){
    	case 'a':
    		  LaSaCylinder();
    		  break;
    	case 'x':
    		return 0;
    	};
    
    };
    //////////////////////////
    //Cylinder Calculation ///
    //////////////////////////
    //LA = Lateral Area    ///
    //////////////////////////
    //SA = Surface Area    ///
    //////////////////////////
    void LaSaCylinder(int radius, int hieght, double LA, double SA);
    { 
    	cout << "What is the radius of the base?\n";
    	cin >> radius;
    	cout << "What is the height of the Cylinder?\n";
    	cin >> height;
    
    	LA = (2 * Pi * radius) * height;
    	SA = LA + (2 * (Pi * (radius^2)));
    
    	cout << LA << " is the Lateral area.\n";
    	cout << SA << " is the Surface area.\n";
    };
    {Insert random techno-babble here}

    {Insert quote from some long gone mofo here}

  6. #6
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    Yeah, that too
    Harry.

    "From one thing, know ten thousand things."

  7. #7

    Thread Starter
    Member
    Join Date
    Sep 2000
    Location
    New Hampshire
    Posts
    32

    Cool

    Wow i never knew that! well that really helps, no that more than helps, that broadens my horizons!

    thanks YoungBuck and Harry.

  8. #8
    Fanatic Member Wynd's Avatar
    Join Date
    Dec 2000
    Location
    In a bar frequented by colossal death robots
    Posts
    772
    A thing I noticed is you spelled 'height' 'hieght', hope that helps.
    Alcohol & calculus don't mix.
    Never drink & derive.

  9. #9
    Fanatic Member Wynd's Avatar
    Join Date
    Dec 2000
    Location
    In a bar frequented by colossal death robots
    Posts
    772
    I tried to make it work, this is what I did:

    Code:
    #include <iostream.h>
    
    const double Pi = 3.1415926535897932384626433832795;
    char choice;
    
    void LaSaCylinder();
    
    int main()
    {
    	cout<<"a.\tCylinder\n";
    	cout<<"b.\tCone\n";
    	cout<<"c.\tPrism\n";
    	cout<<"d.\tPyramid\n";
    	cout<<"--------------\n";
    	cout<<"x.\tExit\n";
    
    	cin>>choice;
    
    	switch (choice)
    	{
    	case 'a':
    		LaSaCylinder();
    		break;
    	case 'x':
    		return 0;
    	}
    }
    //////////////////////////
    //Cylinder Calculation ///
    //////////////////////////
    //LA = Lateral Area    ///
    //////////////////////////
    //SA = Surface Area    ///
    //////////////////////////
    void LaSaCylinder()
    {
    	int radius, height, LA, SA;
    	cout << "What is the radius of the base?\n";
    	cin >> radius;
    	cout << "What is the height of the Cylinder?\n";
    	cin >> height;
    
    	LA = (2 * Pi * radius) * height;
    	SA = LA + (2 * (Pi * (radius^2)));
    
    	cout << LA << " is the Lateral area.\n";
    	cout << SA << " is the Surface area.\n";
    }
    I forgot to add, when you were writing the actual function (don't know what it's called) you put some semicolons between the parenthesis and the openign bracket, and that caused the old-style function thing. Hope this helps!
    Alcohol & calculus don't mix.
    Never drink & derive.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width