Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Please Help me fix my code C++

+3 votes
asked Nov 5, 2020 by Vicent Cotaina Bertó (350 points)
When I execute the code in the online compiler it works. But when I compile it in my Windows it doesnt work properly. The code is the following one:

#include <stdio.h>

#include <iostream>

#define RED "\033[31m"

#define BLUE "\033[34m"

#define RESET   "\033[0m"

int main ()

{

  int p = 0, n = 0, k = 0;

  float positivos[p] = { }, negativos[n] = { };

  float valor, SumaPositivos = 0, SumaNegativos = 0;

  while (valor != 0)

    {

      std::cout << "Escribe tu movimiento bancario: ";

      std::cin >> valor;

      if (valor >= 0)

{

  positivos[p] = valor;

  SumaPositivos += valor;

  p++;

}

      else

{

  negativos[n] = valor;

  SumaNegativos += valor;

  n++;

}

    }

  std::cout << "Tus ingresos son (";

  while (k < p)

    {

      std::cout.setf (std::ios::fixed);

      std::cout.setf (std::ios::showpoint);

      std::cout.setf (std::ios::showpos); //ios estC! en el espacio de nombres std y por eso hay que ponerle std antes.

      std::cout.precision (2);

      std::cout << BLUE << positivos[k] << RESET << "|";

      k++;

    }

  std::cout << ")";

  std::cout << "\nPor lo tanto tu total de ingresos es:" << BLUE << SumaPositivos << RESET;

  k = 0;

  std::cout << "\nTus gastos son (";

  while (k < n)

    {

      std::cout << RED << negativos[k] << RESET << "|";

      k++;

    }

  std::cout << ")";

  std::cout << "\nPor lo tanto tu total de gastos es:" << RED << SumaNegativos << RESET;

  if (SumaPositivos + SumaNegativos >= 0)

    {

      std::cout << "\nTienes un saldo de: " << BLUE << SumaPositivos + SumaNegativos << RESET;

    }

  else

    {

      std::cout << "\nDebes: " << RED << SumaPositivos + SumaNegativos << RESET;

    }

  system ("pause");

  return 0;

}

When I execute it in Windows this happens:

Tus ingresos son (←[34m+2.00←[0m|←[34m+0.00←[0m|)
Por lo tanto tu total de ingresos es:←[34m+2.00←[0m
Tus gastos son ()
Por lo tanto tu total de gastos es:←[31m+0.00←[0m
Tienes un saldo de: ←[34m+2.00←[0m

1 Answer

0 votes
answered Nov 6, 2020 by Peter Minarik (15,580 points)
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...