Click here to Skip to main content
15,887,251 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
#include <iostream>

using namespace std;

class Parallelogram_Area
{
    public: 
    int area;

    Parallelogram_Area(int b, int h);
    {
        Parallelogram_Area::Parallelogram_Area(int b, int h);
        {
            area = b*h;
            cout<<"The area of the parallelogram is: "<<area;
 }
~parallelogram_area();
 {
 ~parallelogram_area::~parallelogram_area();
 cout<<"object destroyed";
}
};

int main()
{
 int= base;
 height;
 cout<<"enter base:= ";
 cin="">>base;
 cout<<"Enter height: ";
 cin>>height;
 Parallelogram_Area Shape1(Base, Height);
}


What I have tried:

I have spent a lot of time surfing the web for solutions and wrecking my brain to solve these 2 errors.
The errors are on line 11 at the '{' symbol
and on the last line at the '}' symbol
I really need help
Posted
Updated 11-Jun-23 19:18pm
v5

Your class still does not look right. It should look like this :
C++
#include <iostream>

using namespace std;

class Parallelogram_Area
{
public: 
   int area;

   Parallelogram_Area( int b, int h )   // constructor
   {
      area = b*h;
      cout << "The area of the parallelogram is: " << area;
   }

   ~Parallelogram_Area()                // destructor
   {
      cout<<"object destroyed";
   }
};
 
Share this answer
 
It's difficult to be sure, because your additions don't help, and the code appears a bit corrupted: use the "Improve Question" widget to paste in a fresh cope and select "Code block" in the paste pop-up.
Then add a copy'n'paste of the whole error message - it contains significant information which may be relevant.

But if I try to uncorrupt it and then indent it correctly:
C++
#include <iostream>

using namespace std;

class Parallelogram_Area
  {
  public:
  int area;
  
  Parallelogram_Area(int b, int h);
    {
    Parallelogram_Area::Parallelogram_Area(int b, int h);
      {
      area = b*h;
      cout<<"The area of the parallelogram is: "<<area;
      }
    ~parallelogram_area();
      {
      ~parallelogram_area::~parallelogram_area();
      cout<<"object="" destroyed";
      }
    };
  
  int main()
    {
    int="" base;
    height;
    cout<<"enter="" base:="" ";
    cin="">>base;
    cout<<"Enter height: ";
    cin>>height;
    Parallelogram_Area Shape1(Base, Height);
    }
The first thing I see is that there is a missing "}" to end the class definition - that will cause an error.

Then there is this bit:
C++
Parallelogram_Area(int b, int h);
  {
  Parallelogram_Area::Parallelogram_Area(int b, int h);
What is the "{" doing there? The semicolon at the end of the previous line indicates a function prototype - which can't have a body, so the "{" will also throw an error.

Fix those, and try compiling again.

You should expect to get syntax errors every day, probably many times a day while you are coding - we all do regardless of how much experience we have! Sometimes, we misspell a variable, or a keyword; sometimes we forget to close a string or a code block. Sometimes the cat walks over your keyboard and types something really weird. Sometimes we just forget how many parameters a method call needs.

We all make mistakes.

And because we all do it, we all have to fix syntax errors - and it's a lot quicker to learn how and fix them yourself than to wait for someone else to fix them for you! So invest a little time in learning how to read error messages, and how to interpret your code as written in the light of what the compiler is telling you is wrong - it really is trying to be helpful!

So read this: How to Write Code to Solve a Problem, A Beginner's Guide Part 2: Syntax Errors[^] - it should help you next time you get a compilation error!

I'm not saying we don't want to help you fix them - sometimes I can't see my own errors because I read what I meant to write - but fixing syntax errors is part of the job, and if you can't do it for yourself people are going to look at you as a bit weird should you get a job in the industry!
 
Share this answer
 
v2
Comments
Andre Oosthuizen 11-Jun-23 6:56am    
Not sure why a score of 1 was given as the above contains the answer regarding incorrect '}' used. My +5!
Patrice T 11-Jun-23 13:11pm    
Code corruption is done on validation of question.
Because code was pasted not enclosed in pre tags.
w3bUs3r 23-Jun-23 21:54pm    
Ok thank you I will review and try to fix those errors you have pointed out

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900