Help with Text Editor and C Executable

Asked

Viewed 43 times

0

I developed a C algorithm for order counting, when I compile inside the Text Editor (ATOM), it performs everything correctly. But when I go to the executable generated in the project folder, it terminates without finishing all functions.

#include <stdio.h>      //CONTROLE DE PEDIDOS
#include <stdlib.h>       //iLLOGICAL
#include <conio.h>          // 21/05/2019

void cabecalho()
{
    printf ("\t|----------------------|\n");
    printf ("\t|     PLAY LANCHES     |\n");
    printf ("\t|                      |\n");
    printf ("\t|     Fechamento       |\n");
    printf ("\t|         de           |\n");
    printf ("\t|       pedidos        |\n");
    printf ("\t|----------------------|\n");
}

int main()
{
    int QtdPedidos, i, j, k;
    int RespTC, RespCerteza, RespCerteza2, RespCerteza3, AcrescentarValor;
    float ValorPedido = 0, TotalPedidos = 0, valor[20];
    float ValorAdicional = 0, TotalGeral = 0, subtracao, ValorSubtraido = 0;
    float TotalGeral2;

    do
    {
        aqui:    cabecalho();

        printf ("\nDigite a quantidade de pedidos: ");
        scanf (" %d", &QtdPedidos);

        printf ("\nTem certeza? [1] SIM [2] N%cO\n", 199);
        scanf (" %d", &RespTC);

        if (RespTC == 2)
        {
            system("cls");
            goto aqui;
            cabecalho();
        }

    } while (RespTC == 2);

        system ("cls");
        cabecalho();
        printf ("\nQuantidade de pedidos = %d\n", QtdPedidos);

        for (i = 1; i <= QtdPedidos; i++)
        {
    inicio: printf ("\nDigite o valor do %d pedido: R$ ", i);
            scanf ("%f", &ValorPedido);

            valor[i] = ValorPedido;
            TotalPedidos = TotalPedidos + ValorPedido;

            printf ("Tem certeza: [1] SIM [2] N%cO\n", 199);
            scanf ("%d", &RespCerteza);

            if (RespCerteza == 2)
            {
                TotalPedidos = TotalPedidos - ValorPedido;
                goto inicio;
            }
        }
            system("cls");
            cabecalho();

            printf ("\nQuantidade de pedidos = %d\n", QtdPedidos);

            printf ("-----------------------------\n");
            for (i = 1; i <= QtdPedidos; i++)
            {
                printf ("Valor pedido %d = R$ %.2f\n", i, valor[i]);
            }
            printf ("-----------------------------\n");
            printf ("\nValor total dos pedidos = R$ %.2f", TotalPedidos);

            printf ("\n\nDeseja acrescentar algum valor: (TROCO...) [1] SIM [2] N%cO\n", 199);
            scanf (" %d", &AcrescentarValor);

            if (AcrescentarValor == 1)
            {
              printf ("\nDigite o valor a ser adicionado: R$ ");
              scanf (" %f", &ValorAdicional);
            }

              TotalGeral = ValorAdicional + TotalPedidos;

              printf ("\nDeseja SUBTRAIR algum valor: [1] SIM [2] N%cO\n", 199);
              scanf (" %d", &RespCerteza3);

              if (RespCerteza3 == 1)
              {
                  printf ("Digite o valor a ser removido: R$ ");
                  scanf (" %f", &ValorSubtraido);
              }


              TotalGeral2 = TotalGeral - ValorSubtraido;

              system("cls");

              cabecalho();
              printf ("\n****************************************************\n");
              printf ("\nQuantidade de pedidos = %d\n", QtdPedidos);
              printf ("_________________________________");
              for (i = 1; i <= QtdPedidos; i++)
              {
                  printf("\n");
                  printf ("Valor pedido %d = R$ %.2f\n", i, valor[i]);
              }
                  printf ("_________________________________\n");
                  printf ("\nValor TOTAL dos pedidos = R$ %.2f\n", TotalPedidos);
              printf ("_________________________________\n");
              printf ("                                                     \n");
              printf ("Valor Adicionado = R$ %.2f\n", ValorAdicional);
              printf ("                                                    \n");
              printf ("\nVALOR TOTAL COM ADI%c%cES = R$ %.2f\n", 128,229, TotalGeral);
              printf ("                                                    \n");
              printf ("\nValor subtraido = R$ %.2f", ValorSubtraido);
              printf ("                                                    \n");
              printf ("\nTOTAL COM ADI%cO E SUBTRA%c%cO = R$ %.2f", 199, 128, 199, TotalGeral2);
              printf ("\n\n**************************************************\n");

              printf ("PRESSIONE ENTER DUAS VEZES PARA SAIR...\n");




  getch();
  getch();
  return 0;
}
  • One of the reasons maybe is the use of conio.hwhich is not recommended. The code has a lot of weird things so it could be a lot of things.

  • I recommend not using goto in your codes

  • Repeated and totally unnecessary code snippets.

  • Thank you, you guys. :)

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.