IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

 C Discussion :

Erreur de switch


Sujet :

C

  1. #1
    Candidat au Club
    Profil pro
    Inscrit en
    Janvier 2012
    Messages
    1
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2012
    Messages : 1
    Points : 2
    Points
    2
    Par défaut Erreur de switch
    Bonjour,
    je commence a peine à apprendre le langage C,
    a part ça je ne m'y connais pas vraiment.
    Enfin bref j'ai commencé a me faire un petit programme menu:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
     
    #include <stdio.h>
    #include <stdlib.h>
     
    int main()
    {
        int menu = 0;
     
        printf("\n\n  == Menu==  \n\n");
        printf("\t1. Cheezburger\n");
        printf("\t2.Chocapic et beaujolais\n");
        printf("\t3.De l'huile\n");
        printf("\t4. Un whisky");
        printf("\n\n\n\n Votre choix?");
        scanf("%d", &menu);
     
        switch (menu);
        {
            case 1:
                printf("\n\nOuais, mon chat ma demandé la meme...");
                break;
            case 2:
                printf("\n\nChasseur dans l'ame");
                break;
            case 3:
                printf("\n\nLes enfant sont adorrables.");
                break;
            case 4:
                printf("\n\ntu te prends pour un 'ricain toi maintenant?");
     
                printf("\n\n  == Menu==  \n\n\t1. Cheezburger\n\t2.Chocapic et beaujolais\n\t3.De l'huile\n\t4. Un Ricard\n\n\n\n Votre choix?");
                int menu4 =0;
                scanf("%d", &menu4);
     
                switch (menu4);
                {
                    case 1:
                        printf("\n\nOuais, mon chat ma demandé la meme...");
                        break;
                    case 2:
                        printf("\n\nChasseur dans l'ame");
                        break;
                    case 3:
                        printf("\n\nLes enfant sont adorrables.");
                        break;
                    case 4:
                        printf("\n\nVoila, enfin une boisson d'homme...");
                        break;
                    default:
                        printf("\n\nQu'est-ce tu raconte?");
                        break;
                }
                break;
            default:
                printf("Qu'est-ce tu raconte?");
                break;
        }
     
        return 0;
     
    }
    et le debugger m'affiche
    -------------- Build: Debug in bordel ---------------

    Compiling: main.c
    C:\...\main.c: In function 'main':
    C:\...\main.c:18: error: case label not within a switch statement
    C:\...\main.c:20: error: break statement not within loop or switch
    C:\...\main.c:21: error: case label not within a switch statement
    C:\...\main.c:23: error: break statement not within loop or switch
    C:\...\main.c:24: error: case label not within a switch statement
    C:\...\main.c:26: error: break statement not within loop or switch
    C:\...\main.c:27: error: case label not within a switch statement
    C:\...\main.c:36: error: case label not within a switch statement
    C:\...\main.c:38: error: break statement not within loop or switch
    C:\...\main.c:39: error: case label not within a switch statement
    C:\...\main.c:41: error: break statement not within loop or switch
    C:\...\main.c:42: error: case label not within a switch statement
    C:\...\main.c:44: error: break statement not within loop or switch
    C:\...\main.c:45: error: case label not within a switch statement
    C:\...\main.c:47: error: break statement not within loop or switch
    C:\...\main.c:48: error: 'default' label not within a switch statement
    C:\...\main.c:50: error: break statement not within loop or switch
    C:\...\main.c:52: error: break statement not within loop or switch
    C:\...\main.c:53: error: 'default' label not within a switch statement
    C:\...\main.c:55: error: break statement not within loop or switch
    Process terminated with status 1 (0 minutes, 0 seconds)
    20 errors, 0 warnings
    Pourriez vous m'aider s'il vous plait?
    Merci d'avance

    Bon bas finalement, j'ai réussi a réglé le problème tout seul meme si je voit pas vraiment la difference
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    #include <stdio.h>
    #include <stdlib.h>
     
    int main()
    {
        int menu = 0;
     
        printf("\n\n  == Menu==  \n\n");
        printf("\t1. Cheezburger\n");
        printf("\t2.Chocapic et beaujolais\n");
        printf("\t3.De l'huile\n");
        printf("\t4. Un whisky");
        printf("\n\n\n\n Votre choix?");
        scanf("%d", &menu);
     
      switch (menu)
      {
        case 1:
            printf("\n\nOuais, mon chat ma demandé la meme...");
            break;
        case 2:
            printf("\n\nChasseur dans l'ame");
                break;
        case 3:
            printf("\n\nLes enfant sont adorrables.");
            break;
            case 4:
            printf("\n\ntu te prends pour un 'ricain toi maintenant?");
     
            printf("\n\n  == Menu==  \n\n\t1. Cheezburger\n\t2.Chocapic et beaujolais\n\t3.De l'huile\n\t4. Un Ricard\n\n\n\n Votre choix?");
            int menu4 =0;
            scanf("%d", &menu4);
     
            switch (menu4)
            {
                case 1:
                    printf("\n\nOuais, mon chat ma demandé la meme...");
                    break;
                case 2:
                    printf("\n\nChasseur dans l'ame");
                    break;
                case 3:
                    printf("\n\nLes enfant sont adorrables.");
                    break;
                case 4:
                    printf("\n\nVoila, enfin une boisson d'homme...");
                    break;
                default:
                    printf("\n\nQu'est-ce tu raconte?");
                    break;
            }
                break;
            default:
                printf("Qu'est-ce tu raconte?");
                break;
        }
     
        return 0;
     
    }

  2. #2
    Membre chevronné
    Avatar de lilington
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juin 2005
    Messages
    681
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : Chine

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Juin 2005
    Messages : 681
    Points : 1 944
    Points
    1 944
    Par défaut
    si tu vois pas la difference c'est un peu grave, il faudrait plutot revoir tes cours de C.
    je vais t'aider en te posant une question:

    que fait ce bout de code et pourquoi?
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    int main()
    {
        int a=0;
        if(a==0);
            return 0;
        print("a n'est pas egal a 0\n");
        return 0;
    }
    c'est le meme principe avec ton switch sauf que la il n'y aura pas d'erreur a la compilation.
    executes ce code et tu comprendra ou est la difference.
    Petit lien vers mon premier jeux SDL2/C
    http://store.steampowered.com/app/72..._Soul_Of_Mask/
    la suite? ca vient,ca vient!

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Erreur de compilation etrange lié a un switch ?
    Par mikebranque dans le forum C++
    Réponses: 3
    Dernier message: 10/07/2012, 13h04
  2. Erreur context switch deadlock
    Par SandyF dans le forum VB.NET
    Réponses: 7
    Dernier message: 19/07/2010, 11h40
  3. Erreur de Switch.. Comment appeler 2 variables?
    Par batnoir dans le forum Général JavaScript
    Réponses: 7
    Dernier message: 23/09/2009, 21h56
  4. [C#]erreur de switch - datatable
    Par igorzup dans le forum ASP.NET
    Réponses: 2
    Dernier message: 08/08/2006, 12h29
  5. Erreur de compilation avec SWITCH et CASE
    Par barbarello dans le forum C++
    Réponses: 4
    Dernier message: 21/01/2006, 21h47

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo