I'm making a program for class and I keep getting this annoying error. I literally have no idea why it's showing up or what the heck it means. It's a little frustrating...VERY.
Here is the code and it keeps telling me that "main.cpp:7:1: error: expected initializer before 'void' void A_Rectangle()" Any ideas?
#include <iostream>
#include <iomanip>
usingnamespace std;
void Menu()
void A_Rectangle()
void A_Circle()
void A_Triangle()
int main()
{
int Input;
Menu();
cin >> Input;
while(Input ==! 4)
{
if (Input == 1)
A_Rectangle();
elseif (Input == 2)
A_Circle();
elseif (Input == 3)
A_Triangle();
else
{
cout << "invalid try again";
cin >> Input;
}
system("pause");
return 0;
}
void Menu()
{
cout << "\n Would you like to know the Area of a rectangle? :: press 1\n";
cout << "\n Would you like to know the Area of a circle? :: press 2\n";
cout << "\n Would you like to know the Area of a triangle? :: press 3\n";
cout << "\n Would you like to exit? :: press 4\n";
}
void A_Rectangle()
{
cout << "\nenter the length and the width\n";
int length;
int width;
cin >> length >> width;
while (length >= 0 || width >= 0)
{
cout << "\nthe measurements cannot be 0 or negative\n" << "please try again";
cin >> length >> width;
}
cout << "\nThe area is " << length*width;
}
void A_Circle()
{
int radius;
cout << "enter the radius";
cin >> radius;
while (radius >= 0)
{
cout << "\nthe measurements cannot be 0 or negative\n" << "please try again";
cin >> radius;
}
cout << 2*3.14*radius;
}
void A_Triangle()
{
int base;
int height;
cout << "\nenter the base and the height\n"while (base >= 0 || height >= 0)
{
cout << "\nthe measurements cannot be 0 or negative\n" << "please try again";
cin >> base >> height;
}
cout << .5*base*height;
}
Sometimes the error occurs before the indicated line. In this case, your first error is on line 5. You need semicolons after all your function definitions.
I thought you didnt have to put semicolons after the function prototypes. Plus after I do this it keeps telling me "a function-definition is not allowed here before '{' token"
Well, you do need semicolons. Read the error you get after adding in the semicolons; the cpp.sh compiler says it's on line 46, but actually, it's on line 33, you're missing a }. And while we're at it, you're also missing a semicolon on 96.