Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

201
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda