Results 1 to 6 of 6

Thread: Code Check

  1. #1
    Aerials
    Guest

    Code Check

    Why won't this work? the compiler says the function is wrong. It's a program that finds ASCII values. pretty straightforward.

    Code:
    */
    #include <iostream.h>
    #include <conio.h>
    int main()
    {
      
      void calc()
      {
      int i;
      int max;
      cin>>max;
      
        for(i=1;i<max;i++)
        {
          char value=i;
          cout<<value<<endl;   
     
        }
      }
      char option;
      cout<<"Continue? c=yes"<<endl;
      cin>>option;
      if(option=='c')
      {
        calc();
      }
      getch();
      getch();
      getch();
      return 0;
    }

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Did it say anything about local function definitions being illegal?

    You have to move it outside of main().

    Oh, and it's <iostream>, not <iostream.h> (you'll need a using namespace std; in there after the includes).
    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

  3. #3
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    What compiler? I suggest you change it for one that's actually compliant with the language specification
    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

  4. #4
    Hyperactive Member Knowledge_is_Et's Avatar
    Join Date
    Dec 2001
    Location
    An Oak.
    Posts
    305
    It doesn't need .h??? I have always needed that in my programs... I'm using Microsoft c++. Why is the .h not needed, and what difference will it make in a program?
    Now returning to the world of VB. Please make sure your seatbelts are securely fastened and all trays are in their upright and locked position.

  5. #5
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    In VC++ 5 and above (what I had), you had support for the newer version of the iostreams library, which is in the header without the .h, matching the rest of the standard library; i.e. <vector>, <list>, <string>, <iostream>, etc.

    The .h versions of the streams are deprecated (in fact VC++7 gives you a warning about this if you try and use them).
    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
    The new headers basically have no change in the interface to the user, but are implemented in a better and more generic way. They also provide a few new features and basically work together better.
    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