Jump to content

Erro error: expected ';' before 'break' break;


Ir para a Solução Solucionado por josedcastro,

Postagens Recomendadas

fiz um código simples mas ao compilar esta apresentano erro em todos os breaks, não entendi o por que . Alguém pode me ajudar ? O erro é o do título.

#include<stdio.h>

 

int main(){

    int i;

    do

    {

        printf("Digite a opção do sabor: \n");

        printf("\t (1) Flocos \n");

        printf("\t (2) Morango \n");

        printf("\t (3) Leite Condensado \n");

        printf("\t (4) Ninho com Nutella \n");

        scanf("%d", &i);

 

    } while ((i < 1) || (1 > 4) );


 

    switch (i)

    {

    case 1:

        printf("\t\t Sua escolha foi flocos")

        break;

       

    case 2:

        printf("\t\t Sua escolha foi Morango")

        break;

 

    case 3:

        printf("\t\t Sua escolha foi Leite Condensado")

        break;

 

    case 4:

        printf("\t\t Sua escolha foi Ninho com Nutella")

        break;

 

    default

        printf("\t\t Opção inválida")

        break;

   

   

    }

 

}

  • Curtir 1
Link to comment
Compartilhe em outros sites

  • Solução

#include <stdio.h>
#include <stdlib.h>

// Main function
int main() {

    // Initialize integer variable 'i'
    int i;

    // Do-while loop for user input
    do {
        // Prompt user to enter the flavor option
        printf("Digite a opção do sabor: \n");

        // Display flavor options
        printf("\t (1) Flocos \n");
        printf("\t (2) Morango \n");
        printf("\t (3) Leite Condensado \n");
        printf("\t (4) Ninho com Nutella \n");

        // Scan user input and store it in 'i'
        scanf("%d", &i);

        // Check if user input is out of bounds (less than 1 or greater than 4)
        if (i < 1 || i > 4) {
            // Display error message if input is invalid
            printf("Opção Inválida. Tente novamente.\n");
        }

    // Continue loop if user input is out of bounds
    } while ((i < 1) || (  i > 4) );

    // Switch statement to handle user input
    switch (i) {
        // Case 1: Flocos
        case 1:
            // Display user's choice
            printf("\t\t Sua escolha foi flocos");
            break;

        // Case 2: Morango
        case 2:
            // Display user's choice
            printf("\t\t Sua escolha foi Morango");
            break;

        // Case 3: Leite Condensado
        case 3:
            // Display user's choice
            printf("\t\t Sua escolha foi Leite Condensado");
            break;

        // Case 4: Ninho com Nutella
        case 4:
            // Display user's choice
            printf("\t\t Sua escolha foi Ninho com Nutella");
            break;
    }

    // Return 0 to indicate successful execution
    return 0;
}

  • Curtir 1
Link to comment
Compartilhe em outros sites

Crie uma conta ou entre para comentar 😀

Você precisa ser um membro para deixar um comentário.

Crie a sua conta

Participe da nossa comunidade, crie sua conta.
É bem rápido!

Criar minha conta agora

Entrar

Você já tem uma conta?
Faça o login agora.

Entrar agora


×
×
  • Create New...