Reputation: 13
I'm getting an error on line 4:
expected constructor, destructor, or type conversion before ';' token
I'm pretty weak at this point when it comes to functions, so I know that there is something wrong with my function declaration(?). Anyone have any suggestions? Thanks in advance...
#include <iostream>
using namespace std;
shapeDetermine (char letter);
int main()
{
char letter;
int side, area, base, height; // lengths to be used in calculating area
cout << "Enter the first letter of the shape:";
cin>> letter;
system ("pause");
return 0;
}
Added:
void shapeDetermine (char shape)
{
int side, area, base, height; // lengths to be used in calculating area
if (letter == 's') //determine what shape is used - square
{
cout<< " Enter the length of side of square:";
cin>> side;
area = side * side; // formula for area of square
cout<< " The area of the square is "<< area<< " cm."<<endl;
}
else if (letter =='t') // triangle
{
cout<< " Enter the height of triangle:";
cin>> height;
cout<< " Enter length of base of triangle:"<< endl;
cin>> base;
area = (base * height) / 2; // formula for area of triangle
cout<< " The area of the triangle is "<< area<< " cm."<<endl;
}
else
{
cout<<" Invalid shape entered."<< endl; // for any character other than s||t
}
}
Upvotes: 1
Views: 1788
Reputation: 13946
You're not declaring a return type for shapeDetermine
. If for example it is supposed to return an int, it should be declared:
int shapeDetermine(char letter);
Updating to respond to the new code the OP posted:
That new code is fine. However, if it appears after main()
in the file (or in another file) then you still need to declare a function prototype for it before you call it. Given the function definition you've posted, the prototype would be:
void shapeDetermine(char shape);
Another update to address the comments:
You need to actually call the function. In your as-posted code for main()
you aren't calling shapeDetermine()
anywhere. Try changing your main()
to read like this:
cout << "Enter the first letter of the shape:";
cin>> letter;
shapeDetermine(letter);
system ("pause");
Upvotes: 4
Reputation:
So far I can see you have declared the function shapeDetermine but in its declaration you haven't specified a return type. I think you must specify one even if it is void.
Upvotes: 0