Click here to Skip to main content
15,881,967 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
#include<iostream>
using namespace std;
class Dist
{
    int feet;
    float inches;
public:
    enter()
    {
        cout<<"\nenter feet ";
        cin>>feet;
        cout<<"\nenter inches";
        cin>>inches;
    }
    display()
    {
        cout<<feet<<"'-"<<inches;
    }
    scale(Dist &d1, float scalefactor)
    {
        d1.feet= d1.feet*scalefactor;
        d1.inches=d1.inches*scalefactor;
        while(d1.inches>=12)
            {
                d1.inches=12-d1.inches;
                d1.feet++;
            }

};
main()
{
    Dist d1,d2;
    d1.enter();
    d1.scale(d1,0.5);
    d1.display();

} //error is in this line


What I have tried:

I tried to look for any syntax error and commented the whole main function but the error is still there.
Posted
Updated 29-Sep-22 18:59pm

You are missing a close curly bracket (and have a spurious semicolon before main
If you sort your indentation out, it becomes more obvious:
C++
class Dist
{
    int feet;
    float inches;
public:
    enter()
    {
       ...
    }
    display()
    {
       ...
    }
    scale(Dist &d1, float scalefactor)
    {
       ...
       while(d1.inches>=12)
       {
          ...
       }
    }
main()
    {
       ...
    }
--- requires a close curly bracket here to end the class definition ---
 
Share this answer
 
Comments
Richard MacCutchan 27-Feb-20 5:05am    
I think it just needs the closing brace for the scale method. The closing brace and semi-colon before main closes the class definition.
Well, at a glance, the 'scale' method in the 'Dist' class does not have a closing '}'. Sometimes compiler errors are a bit mysterious and other times, they mean exactly what they say. It is up to you to figure out the difference.
 
Share this answer
 
In addition to OG's answer, I think
C++
d1.inches=12-d1.inches;
should read
C++
d1.inches -= 12;
instead.
 
Share this answer
 

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