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
}
}
You’re not declaring a return type for
shapeDetermine. If for example it is supposed to return an int, it should be declared: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:Another update to address the comments:
You need to actually call the function. In your as-posted code for
main()you aren’t callingshapeDetermine()anywhere. Try changing yourmain()to read like this: