Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

193
Vistas
Why my while loop in not getting repeated in this switch case?
#include <stdio.h>
int main()
{
    int a;
    scanf("%d", &a);
    int if_again = 1;
    int c = 1;
    switch (a)
    {
    case 1:
        while (if_again == 1)
        {
            scanf("%d", c);
            if (c == 1)
            {
                if_again == 1;
            }
            else
            {
                if_again == 0;
            }
        }
    }
    return 0;
}

It is getting terminated after giving 1 two times only, but it should keep on getting repeated until 0 is entered. What is wrong with my code?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

scanf needs the base address of a variable you give it. So scanf("%d, c); needs to be scanf(%d, &c);

The following code is also wrong:

if (c == 1)
{
   if_again == 1;
}

The compiler thinks that you are comparing "if_again" with 1. I think you are trying to set the variable to 1? In that case do this:

if (c == 1)
{
   if_again = 1;
}

The same is true for the else statement.

Also, why is there a switch statement? If you want to see it a is 1, then just to an if

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda