Results 1 to 15 of 15

Thread: A Little Help!?!?

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2002
    Location
    Whaaaaat...........
    Posts
    44

    A Little Help!?!?

    Hey people, I need some help, I got a new book, and it tells right off the bat to do this to write out all the ASCII characters:

    PHP Code:
    #include <iostream>

    main <void>
    {
        
    unsigned char ASCIIValue 0;

        while (
    ASCIIValue 256)
        
            
    std::cout.put (ASCIIValue);
            
    ASCIIValue ++;
        

        return 
    0;

    Ok so why the hell dose it not work, this book is using VC++, and im using the same complier, so could osme one plz tell me ***?

    Gives errors do to ";" not being behind < or something.
    A way to find answers, is to ask questions, for a question that has been asked may seem stupid for 5 minutes, but a question never asked will remain unknown forever.

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    int main(void)
    instead of
    main <void>
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3
    Hyperactive Member
    Join Date
    Sep 2001
    Posts
    396

    Re: A Little Help!?!?

    Code:
    #include <iostream>
    
    int main (void)
    {
      unsigned char ASCIIValue = 0;
    
      while (ASCIIValue <= 255)
      {
        std::cout.put (ASCIIValue);
        ASCIIValue ++;
      }
    
      return 0;
    }
    You forgot to put curly brackets for the while loop

    Edited: the upper limit of unsigned char is 255

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    If what you first posted is what your book told you to do then throw it away.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  5. #5
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Or send it to me so I can televise its ritual destruction, followed by posting the pieces to the publisher.

    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  6. #6
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    How about ritually destructing the author?
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  7. #7

    Thread Starter
    Member
    Join Date
    Nov 2002
    Location
    Whaaaaat...........
    Posts
    44
    lol yeah it was a type from the book..
    A way to find answers, is to ask questions, for a question that has been asked may seem stupid for 5 minutes, but a question never asked will remain unknown forever.

  8. #8

    Thread Starter
    Member
    Join Date
    Nov 2002
    Location
    Whaaaaat...........
    Posts
    44
    bah I meant typo
    A way to find answers, is to ask questions, for a question that has been asked may seem stupid for 5 minutes, but a question never asked will remain unknown forever.

  9. #9
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Bad enough that a c++ book gives main no return type. That's a very bad manner that shouldn't even be started.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  10. #10

    Thread Starter
    Member
    Join Date
    Nov 2002
    Location
    Whaaaaat...........
    Posts
    44
    I know what you mean, it should have been left main ().
    A way to find answers, is to ask questions, for a question that has been asked may seem stupid for 5 minutes, but a question never asked will remain unknown forever.

  11. #11
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    No he means the return type, like
    Code:
    int Main (...)
    I guess.
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  12. #12

    Thread Starter
    Member
    Join Date
    Nov 2002
    Location
    Whaaaaat...........
    Posts
    44
    I know I meant the return type, thats why I said leave it empty instead of putting void main ( ) main (void)
    A way to find answers, is to ask questions, for a question that has been asked may seem stupid for 5 minutes, but a question never asked will remain unknown forever.

  13. #13
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Leave what empty?

    The definition is:
    Code:
    int main(int argc, char **argv);
    You can miss off argv, or argc AND argv. Since we're talking about C++, a blank argument list () is acceptable. In C, if main did not require arguments, it should be given as:
    Code:
    int main(void);
    because in C, a blank argument list means it can take any number, rather than taking none, as in C++.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  14. #14
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    it could still have been a typo, because there's return 0;
    what does the other examples in the book have?
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  15. #15
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Don't they ever take a look at their books?
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

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