Thread: Can someone with a brain point out something here...

  1. #1
    Utter insanity
    Join Date
    Jan 2004
    Posts
    19

    Question Can someone with a brain point out something here...

    Because apparently I don't have one. This code is from Teach Yourself C++ in 21 Days, listing 5.7, which is supposed to be written with the ASCII standard. I get the error message ISO C++ forbids declaration of ' from Dev C++ on line 25 (an opening brace for the function VolumeCube). The code is exactly as it appears in the book, save for "using namespace std". Thanks in advance.

    Code:
    #include <iostream>
    using namespace std;
    
    int VolumeCube(int length, int width = 25, int height = 1);
    
    int main()
    {
        int length = 100;
        int width = 50;
        int height = 2;
        int volume;
        
        volume = VolumeCube(length, width, height);
        cout << "First volume equals: " << volume << "\n";
        
        volume = VolumeCube(length, width);
        cout << "Second time volume equals: " << volume << "\n";
        
        volume = VolumeCube(length);
        cout << "Third time volume equals: " << volume << "\n";
        return 0;
    }
    
    VolumeCube(int length, int width, int height)
    {
        return (length * width * height);
    }
    "I merely took the energy it takes to pout and wrote some blues." - Duke Ellington

  2. #2
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    Code:
    int VolumeCube(int length, int width, int height)
    {
        return (length * width * height);
    }
    So easy to make those mistakes
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  3. #3
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    Posts
    856
    Your implementation of VolumeCube() lacks a return type. Type int next to it.

  4. #4
    Utter insanity
    Join Date
    Jan 2004
    Posts
    19
    @#$! my eyes! Thank you. Apparently I need to get my glasses checked....
    "I merely took the energy it takes to pout and wrote some blues." - Duke Ellington

  5. #5
    Handy Andy andyhunter's Avatar
    Join Date
    Dec 2004
    Posts
    540
    Well I guess I can't help.

  6. #6
    Registered User
    Join Date
    Feb 2002
    Posts
    13
    IT works perfect on VS 6.0 No further changes needed... regards
    Ok...

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > IT works perfect on VS 6.0 No further changes needed
    So what does that tell you about
    a) the book in question
    b) your compiler.
    For me, it tells me that the book and VS6 have the same bug.

  8. #8
    Registered User
    Join Date
    Feb 2002
    Posts
    13
    intresting if you can speak german refer here


    http://web.dadanini.com:7980/books/C...gen/kap05.html


    if english here

    http://vip.6to23.com/dcyu/ANSICPP/No1/5.html


    good luck my friend...
    Last edited by Shahram_z; 12-28-2004 at 01:20 AM.
    Ok...

  9. #9
    Utter insanity
    Join Date
    Jan 2004
    Posts
    19
    Quote Originally Posted by Shahram_z
    intresting

    if english here

    http://vip.6to23.com/dcyu/ANSICPP/No1/5.html


    good luck my friend...
    No se habla en ingles; and no speak Chinese either....

    Yeah, this is a old copy of that book, I got it off a discount rack for $3... Even as little as I know about C++, I've seen some goofball mistakes in the code here and there, mostly just typos. That was one that I didn't catch for some reason...

    I do know that some compilers, such as Borland's, have their own dialect of C++ that they may use instead of ANSI. I have Borland's IDE as well, and I never could get it to accept a single bit of ANSI-compliant code; in either C or C++; from various sources both in books and online. I finally gave up and got Dev C++; which is having it's share of problems as well now.

    Thank y'all for all the help.
    "I merely took the energy it takes to pout and wrote some blues." - Duke Ellington

  10. #10
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    >> ...Dev C++; which is having it's share of problems as well now.
    Well, failing to compile invalid code isn't exactly a problem in my book

    If Dev C++ (which uses the MinGW port of GCC) fails to compile some code from that book - you can safely assume the book is incorrect or you typed it in wrong.

    gg

  11. #11
    Utter insanity
    Join Date
    Jan 2004
    Posts
    19
    Actually, it was about a dozen versions or so out of date. Though I'm beginning to think I was ripped on the book. I've gotten to chapter 6, which is implementing basic classes and setting them up as include files. Unfortunately, the second program that you build a custom include for is so seriously messed up it isn't even funny. I'm going to look around on this site for a tutorial on classes, and see how to fix this mess. I'm getting around 100 error messages right now; after I combined the .hpp file into the source so I could see if the compiler simply didn't like me leaving my custom includes in their own folder on e:\. Only 25 or so before hand in the source... The ones I can see are missing functions being called here and there.

    Whats some good recommendations for books? I do have a more advanced book on low-level interrupts and functions which weighs about the same as a 340 six pack, but I kinda doubt I'd be able to do much more than get a headache and some frustration with that.
    "I merely took the energy it takes to pout and wrote some blues." - Duke Ellington

  12. #12
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >I'm beginning to think I was ripped on the book
    $3 will buy you a decent sandwich. Decent sandwiches are worth their weight in gold.

    >Whats some good recommendations for books?
    Accelerated C++ by Andrew Koenig and Barbara Moo.
    My best code is written with the delete key.

  13. #13
    Handy Andy andyhunter's Avatar
    Join Date
    Dec 2004
    Posts
    540
    If you are looking for good cheap books take the suggestions from the people on this board and then go to amazon.com and check out to see if they are selling a used copy of the book.

    I started doing it to get books that weren't in print anymore but I now buy the majority of my books that way. I have never had any complaints and most of the time you can get the books for around 30% - 50% off the list price.
    i don't think most standard compilers support programmers with more than 4 red boxes - Misplaced

    It is my sacred duity to stand in the path of the flood of ignorance and blatant stupidity... - quzah

    Such pointless tricks ceased to be interesting or useful when we came down from the trees and started using higher level languages. - Salem

  14. #14
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  15. #15
    Utter insanity
    Join Date
    Jan 2004
    Posts
    19
    Thanks y'all. I have ordered from Amazon before; not much though. The only book I really want is close to $30 used.
    "I merely took the energy it takes to pout and wrote some blues." - Duke Ellington

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Human brain and programing
    By avgprogamerjoe in forum A Brief History of Cprogramming.com
    Replies: 26
    Last Post: 08-27-2007, 04:48 PM
  2. brain vs. computer (brain wins hands down)
    By hk_mp5kpdw in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 09-17-2003, 08:41 PM
  3. fixed point / floating point
    By confuted in forum Game Programming
    Replies: 4
    Last Post: 08-13-2002, 01:25 PM
  4. Re: Girlfriend Post
    By PsychoBrat in forum A Brief History of Cprogramming.com
    Replies: 57
    Last Post: 05-13-2002, 06:11 AM