Different result in output format using the same function

0

I have a program that when the report function is invoked prints with the name alignment correctly, but when the same function is called with a second file the alignment changes and justifies the column of names on the right:

# include <iostream>
# include <fstream>
# include <cstring>
# include <cstdlib>
# include <iomanip>
using namespace std;
void agregar();
void incremento();
void reporte(char[]);
int main(){
    system("color 1F");
    agregar();
    char nom1[]="salarios.txt";
    reporte(nom1);
    system("pause");
    incremento();
    char nom2[]="salariosnuevos.txt";
    system("cls");

    reporte(nom2);
}
void agregar()
{   ofstream f;
    f.open("salarios.txt",ios::app);
    int n;
    string ci,nombre;
    double sal;
    cout << "Cuantos empleados:";cin >> n;
    for (int i=0;i<n;i++){
        cout <<"Cedula:";cin >> ci;
        cout <<"Nombre:";cin >> nombre;
        cout <<"Salario:";cin >> sal;
        f << ci<<";"<<nombre<<";"<<sal<<endl;
    }
    f.close();

 }
void reporte(char x[]){
    ifstream f;
    f.open(x);
    char cad[30];
    char *ci1,*nom1,*sal1;
    cin.clear();
    //cin.ignore(INT_MAX);
    double sum=0;
    cout <<"          REPORTE DE SALARIOS\n";
    cout <<"          ===================\n";
    cout <<"=CEDULA======NOMBRE=====SALARIO====\n";
    while(f>>cad){
        ci1=strtok(cad,";");
        nom1=strtok(NULL,";");
        sal1=strtok(NULL,";");
        cout <<setw(1)<<"|"<<ci1 <<"|"<<setiosflags(ios::left)<<setw(15)<<nom1 <<"|"<<setw(5)<<sal1<<"|"<<setw(3)<<endl;
        //cout << setiosflags(ios::left) << setw(80) << "0123456789" << std::endl;
        double salario=atof(sal1);
        sum=sum+salario;
     }
     cout <<"===============================\n";
     cout <<setw(1)<<"TOTAL:"<<setiosflags(ios::right)<<setw(23)<<sum << endl;
     f.close();
}
void incremento(){
    ifstream f1;
    f1.open("salarios.txt");
    ofstream f2;
    f2.open("salariosnuevos.txt");
    char *ci1,*nom1,*sal1,cad[30];
    double inc,salnuevo,aux;
    while(f1>>cad){
        ci1=strtok(cad,";");
        nom1=strtok(NULL,";");
        sal1=strtok(NULL,";");
        aux=atof(sal1);
        if (aux<2000)
            inc=0.1;
        else
            if (aux<5000)
                inc=0.07;
            else
                if(aux<7500)
                    inc=0.05;
        salnuevo=aux*inc+aux;
        f2<<ci1<<";"<<nom1<<";"<<salnuevo<<endl;
     }
     f1.close();
     f2.close();
     cout  << "Incremento realizado...\n";
}
    
asked by Orlando 08.11.2018 в 16:37
source

0 answers