Проблемы с форматированием текста - PullRequest
0 голосов
/ 23 октября 2019

Я пытаюсь закончить свою программу. Программа запросит n сотрудников из компании, затем name, salary и sale of the month. Выходные данные будут отображать предыдущую информацию плюс comission, net salary и total каждого из них.

Для лучшего понимания это будет вывод:

Name               Salary    Sale of the month           Comission    Net salary 
Elena Gomez       2000.00              1000.00              35.00       2035.00
Elle Johns        4000.00              1345.00              60.53       4060.53 
Stefan Cox        3200.00              4000.00             216.00       3416.00 
Total             9200.00              6345.00             311.53       9511.53 

Employee with upper comission: Stefan Cox 216.00
Employee with lower comission: Elena Gomez 35.0
Employee with upper net salary: Elle Johns 4060.53
Employee with lower net salary: Elena Gomez 2035.00

Employees with sales upper than the prom (US$2115)

Name               Salary    Sale of the month           Comission    Net salary
Stefan Cox        3200.00              4000.00             216.00       3416.00 

Это код main:

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#define NUMBER_OF_STRING 6
#define MAX_STRING_SIZE 50

void print_array(const char arr[][MAX_STRING_SIZE]);
void upper_comission (float [], char [5][50],char [5][50], int);
void lower_comission (float[], char [5][50],char [5][50], int);
void upper_netsalary (float [], char [5][50],char [5][50], int);
void lower_netsalary (float[], char [5][50],char [5][50], int);
float prom_sales(float[], int);

int main ()
{
    int numemployees, cont=0;
    float salary[50], salnet[50], sale[50], comission[50], ind=0, totalsales=0,totalsalary=0,totalsalnet=0, totalcomission=0, prom;
    char header[0], nom[5][50], lastname[5][50];

char arr[NUMBER_OF_STRING][MAX_STRING_SIZE] =
    { "Name",
      "salary",
      "Sale of the month",
      "Comission",
      "Net salary"
    };

    printf("Enter # of employees to consult: \n");
    scanf("%d",&numemployees);

     for(int i=0; i<numemployees; i++)
             {

                  printf("Enter employee's %d name : ",i+1);
                  scanf("%s", &nom[i]);

                  printf("Enter employee's %d last name : ",i+1);
                  scanf("%s", &lastname[i]);

                  printf("Enter employee's %d salary : ",i+1);
                  scanf("%f", &salary[i]);

                  printf("Enter sale of the month of the employee %d : ",i+1);
                  scanf("%f", &sale[i]);

                  system("cls");
            }

    print_array(arr); // function that shows the headers

    for(int i=0; i<=numemployees; i++)
    {

     if (sale[i] <= 1000)
        {
            comission[i]=sale[i] * 0.035;
            salnet[i]=salary[i]+comission[i];
        }

        if (sale [i] < 2000 || sale [i] > 1000)
        {
            comission[i]=sale[i] * 0.045;
            salnet[i]=salary[i]+comission[i];
        }

        if (sale [i] > 2000)
        {
            comission[i]=sale[i] * 0.054;
            salnet[i]=salary[i]+comission[i];
        }

            totalsales+=sale[i];
            totalsalary+=salary[i];
            totalcomission+=comission[i];
            totalsalnet+=salnet[i];

    printf("%25s %s %25.2f   %25.2f  %25.2f   %25.2f \n",nom[i],lastname[i], salary[i], sale[i], comission[i],salnet[i]);
    }


    printf("\t\tTotal %25.2f   %25.2f  %25.2f   %25.2f\n",totalsalary, totalsales, totalcomission, totalsalnet);


    upper_comission(comission, nom,lastname, numemployees);
    lower_comission(comission, nom,lastname, numemployees);
    upper_netsalary(salnet, nom,lastname, numemployees);
    lower_netsalary(salnet, nom,lastname, numemployees);
    prom=prom_sales(sale, numemployees);


    printf("\n");
    printf("Employees with sales upper than the prom (RD$%.2f) \n",prom);

    for (int i=0; i < numemployees; i++)
    {

    if (sale[i] > prom)
    {
        print_array(arr);
        printf("%25s %s %25.2f   %25.2f  %25.2f   %25.2f \n",nom[i],lastname[i], salary[i], sale[i], comission[i],salnet[i]);
    }

    }

    return 0;
}

Функции:


void print_array(const char arr[NUMBER_OF_STRING][MAX_STRING_SIZE])
{
    for (int i = 0; i < NUMBER_OF_STRING; i++)
    {
        printf("%25s ", arr[i]);

        if (i == 5)
        {
            printf("%25s \n", arr[i]);
        }

    }
}
void upper_comission (float comission[],char nom[5][50],char lastname[5][50], int n)
{
    int i, nombre, apellido;
    float mayor;
    char name;

    for (i=0; i<n; i++)
    {
        mayor = comission[0];

        if (mayor < comission[i])
        {
            mayor = comission[i];
            nombre=i;
            apellido = i;
        }

    }
    printf("Employee with upper comission: %s %s %.2f \n",nom[nombre],lastname[apellido], mayor);
}

void lower_comission (float comission[],char nom[5][50],char lastname[5][50], int n)
{
    int i, nombre, apellido;
    float menor;

    for (i=0; i<n; i++)
    {
        menor = comission[0];

        if (menor > comission[i])
        {
            menor = comission[i];
            nombre=i;
            apellido=i;
        }

    }
    printf("Employee with lower comission: %s %s %.2f \n",nom[nombre],lastname[apellido], menor);
}

void upper_netsalary (float salnet[],char nom[5][50],char lastname[5][50], int n)
{

int i, nombre, apellido;
    float mayor;

    for (i=0; i<n; i++)
    {
        mayor = salnet[0];

        if (mayor < salnet[i])
        {
            mayor = salnet[i];
            nombre=i;
            apellido=i;
        }

    }
    printf("Employee with upper net salary: %s %s %.2f \n",nom[nombre],lastname[apellido], mayor);
}

void lower_netsalary (float salnet[], char nom[5][50],char lastname[5][50], int n)
{
int i, nombre, apellido;
    float menor;

    for (i=0; i<n; i++)
    {
        menor = salnet[0];

        if (menor > salnet[i])
        {
            menor = salnet[i];
            nombre=i;
            apellido=i;
        }

    }
    printf("Employee with lower net salary: %s %s %.2f \n",nom[nombre],lastname[apellido], menor);
}

float prom_sales(float sale[], int n)
{
    float prom=0;
    int i;

    for (i=0; i<n;i++)
    {
        prom += sale[i];
    }


return prom/n;
}

Мои проблемы следующие:

  • В выходных данных отображается то же имя, когда оно должно быть с соответствующим названием комиссионного / чистого оклада [исправлено] :
 Name                    salary                  Sale of the month                       Comission                       Net salary
marie gomez                                500.00                                  850.00                                   38.25                                  538.25
luca grus                                  856.00                                   80.00                                    3.60                                  859.60
Total                   1356.00                                                            930.00                                           41.85                                         1397.85
Employee with upper comission: luca grus 38.25
Employee with lower comission: luca grus 3.60
Employee with upper net salary: luca grus 859.60
Employee with lower net salary: luca grus 538.25

Employees with sales upper than the prom (RD$465.00)
Name                    salary                  Sale of the month                       Comission                       Net salary
marie gomez              500.00          850.00          38.25           538.25


  • Раньше программа печатала следующие коды, такие как the employee with upper comission и т. Д. Но теперь это не отображается. [исправлено]
  • Вывод должен быть хорошо выровнен, я попытался с printf("%25s");, но я не получил вывод, как в начале. [исправлено]

Я не знаю, если я делаю что-то не так, пожалуйста, проверьте это. Заранее спасибо.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...