Basically the idea is to center a string. I selected the total length to equal 80. I know there is no fail safe placed into this program. I know there is another way to do this. I am stuck in a way. The program works, but I think I am doing it the hard way. any information or advice would be helpful.
#include <iostream>
#include <string>
int main(void)
{
using namespace std;
string sname;
cout << "Enter the a sentence " <<endl;
getline(cin,sname);
int s = sname.size();
int pad1 = (80 - s)/2;
int pad2 = pad1;
for (int f = 0; f < pad1; f++)
{
cout << " ";
++f;
}
cout << sname;
for (int e = 0; e < pad2; e++)
{
cout << " ";
++e;
}
cout << endl;
}
Thank you in advance.