PDA

Click to See Complete Forum and Search --> : Can you figure out these errors?


Aug 22nd, 2000, 01:54 PM
Here is the 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



error C2062: type 'void' unexpected
error C2084: function 'void __cdecl charac(void)' already has a body



I cant figure it out...
Can you?

parksie
Aug 22nd, 2000, 01:59 PM
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 ';'.

Aug 22nd, 2000, 02:06 PM
Thanks, it was the ":" thats was making both errors. I couldnt see the difference on my screen though.

parksie
Aug 22nd, 2000, 02:09 PM
I had to run it through the compiler before I noticed...

V(ery) Basic
Aug 23rd, 2000, 07:13 AM
I noticed it the moment parksie pointed it out.

parksie
Aug 23rd, 2000, 12:43 PM
Yeah, yeah. Like hell you did ;)