//main

#include <iostream>
#include <cstdlib>
using namespace std;
#include "libro.h"
int main()
{
    test ab;
    cout<<"enter width limit";
    int length;
    cin>>length;
    ab.alternate(length);
}

//implementation

#include <iostream>
#include <cctype>
#include <cstdlib>
using namespace std;
#include "libro.h"

int test::alternate(int width)
{
    //for odd, 3 char-ellipsis
    if(width%2==1)
    {
         keep=width-3;
    }
    //for even, 4 char-ellipsis
    else if(width%2==0)
    {
        keep=width-4;
    }

    return keep_per_end=keep/2;
}

//interface

#ifndef LIBRO_H_INCLUDED
#define LIBRO_H_INCLUDED
#include <iostream>
using namespace std;

class test
{
    public:
    //check if even or odd 
    int alternate(int width);
    int keep_per_end;
    int keep;
};
#endif // LIBRO_H_INCLUDED

What are you trying to do?


Also you don't need the second if, just else!

And your return is hinky!

return keep_per_end=keep/2;

You need to add white space to your equations to make problems more apparent!

return keep_per_end = keep / 2;

I'm not sure what you're trying to do but instead do

keep_per_end = keep / 2;
  return keep_per_end;

the function is supposed to find out the number of characters at each end of a string it is supposed to store. and insert ... if odd and .... if even

//main

#include <iostream>
#include <cstdlib>
using namespace std;
#include "libro.h"
int main()
{
    test ab;
    cout<<"enter width limit";
    int length;
    cin>>length;
    ab.alternate(length);
}

You're checking for odd 1,3,5,7,9, etc.
And even 2,4,6, 8, etc.

But you're subtracting 3 from odd making it even but removing
3 characters?
When subracting 4 from even, you're removing 4 characters?

What are you trying to align to? You mention insert, do you mean append a space to make odd even? Then why is even being adjusted by four?

I'm still not seeing the required functionality!

That last line I pointed out typically saves the result of the = as a logical compare, not the length.
Break it into two lines.

the keep_per_end will stay valid as long as the class is within scope.

modified my implementation

#include <iostream>
#include <cctype>
#include <cstdlib>
using namespace std;
#include "libro.h"

int test::alternate(int width)
{
    //for odd, 3 char-ellipsis
    if(width%2==1)
    {
        if(width)
        {
         keep=width-3;
        }
    }
    //for even, 4 char-ellipsis
    else if(width%2==0)
    {
        if(width)
        {
        keep=width-4;
        }
    }

    keep_per_end=keep/2;
    return keep_per_end;
}
int test::alternate(int width)
{
    //for odd, 3 char-ellipsis
    if(width%2==1)
    {
         keep=width-3;
    }
    //for even, 4 char-ellipsis
    else
    {
        if(width)
        {
        keep=width-4;
        }
    }

    keep_per_end=keep/2;
    return keep_per_end;
}
int main()
{
    test ab;
    cout<<"enter width limit";
    int length;
    cin>>length;
    ab.alternate(length);
   return 0;
}

I missed it....

int test::alternate(int width)
{
  keep = 0;
    //for odd, 3 char-ellipsis
    if(width%2==1)
    {
         keep=width-3;
    }
    //for even, 4 char-ellipsis
    else
    {
        if(width)
        {
        keep=width-4;
        }
    }

    keep_per_end=keep/2;
    return keep_per_end;
}

Was that it?
I only noticed that it wasn't initialized in a zero state and compilers consider that an error! I find sometimes I have to initialized something even though I know the code will change it but the compiler doesn't see that state!

Rats.
I just cut your code into a test bench and had no errors.

Try putting it all in one file.

class definition

Then your two functions and try that!

What's your compiler error?

I thought I posted this line but don't see it so....

Combine them all into the same file and try again.

Sounds like a header problem. But I don't see any. I combined mine into the same file and compiled fine.

This question has already been answered. Start a new discussion instead.