Results 1 to 6 of 6

Thread: Can you figure out these errors?

  1. #1
    Guest

    Post

    Here is the code...

    Code:
    ///////////////////////////////////////////////////////////////////
    //header statements
    #include <iostream.h>
    #include <stdlib.h>
    
    ///////////////////////////////////////////////////////////////////
    //functions
    void size();
    void charac():
    
    ///////////////////////////////////////////////////////////////////
    //main
    void main()
    {
    	cout<<"Hello, I am Disposable Hero A59."<<endl;
    	cout<<""<<endl;
    	size();
    	charac();
    }	
    
    ///////////////////////////////////////////////////////////////////
    //size()
    void size()
    {
    	cout<<"The size of a char is\t"<<sizeof(char)<<" bytes"<<endl;
    	cout<<"The size of a short is\t"<<sizeof(short)<<" bytes"<<endl;
    	cout<<"The size of an int is\t"<<sizeof(int)<<" bytes"<<endl;
    	cout<<"The size of a long is\t"<<sizeof(long)<<" bytes"<<endl;
    	cout<<"The size of a float is\t"<<sizeof(float)<<" bytes"<<endl;
    	cout<<"The size of a double is\t"<<sizeof(double)<<" bytes"<<endl;
    	cout<<""<<endl;
    	cout<<"The size of the variables was found by using the 'sizeof()' function."<<endl;
    	system("pause");
    	system("cls");
    }
    
    ///////////////////////////////////////////////////////////////////
    //charac()
    void charac()
    {
    	cout<<"These are the characters from 32 to 128"<<endl;
    	cout<<""<<endl;
    	for(int i=32; i<128; i++)
    	{
    		cout<<(char)i;
    	}
    	cout<<""<<endl;
    	cout<<"These were found by using the '(char)' function."<<endl;
    	system("pause");
    	system("cls");
    }
    And here are the errors

    Code:
    error C2062: type 'void' unexpected
    error C2084: function 'void __cdecl charac(void)' already has a body
    I cant figure it out...
    Can you?

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Try using 'int main' rather than 'void main', then adding a 'return 0' at the end of the main() function.

    Also, what are your line numbers on the errors, please.

    One edit later...

    After your prototype of charac, you have a ':' not a ';'.
    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
    Guest
    Thanks, it was the ":" thats was making both errors. I couldnt see the difference on my screen though.

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    I had to run it through the compiler before I noticed...
    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

  5. #5
    Fanatic Member
    Join Date
    Apr 2000
    Location
    Whats a location?
    Posts
    516
    I noticed it the moment parksie pointed it out.
    Courgettes.

  6. #6
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Yeah, yeah. Like hell you did
    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

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