User forums > Using Code::Blocks

variables problem ! (please help a noob)

(1/1)

bingofuel:
Hi guys,
I am new on this forum and I'm a beginner in programming in C and today I feel the need to ask for your help because I am stuck on something that really annoys me a lot.
I have an issue concerning variables that keep letters (sorry if the terms are not correct, I am french and I don't know how it is called in english)
Anyway, have a look on this and please tell me why the "error..." message appears TWICE when I don't press 'r' but an other letter instead!? :shock:

--- Code: ---#include <stdio.h>
#include <stdlib.h>


int main()
{
    char menu=0;

    printf("Regles du jeu\n  BLABLABLA...\n");
    printf("Appuyer sur R pour retourner au menu\n\n");
    scanf("%c", &menu);
    while (menu !='r')
    {
        printf("Erreur, Appuyer sur R pour retourner au menu\n ");
        scanf("%c", &menu);

    }


    return 0;

}

--- End code ---

thlgood:
I'm a Chinese ,I'm not good at english

here is my programs writter for you


--- Code: ---#include <stdio.h>
int main()
{
    char menu=0;
    while (menu !='r')
    {
        printf("error\n");
        scanf("%c\n", &menu);
    }
    return 0;
}

--- End code ---

--- Code: ---#include <stdio.h>
#include <conio.h>
int main()
{
    char menu=0;
    while (menu !='r')
    {
        printf("error\n");
        menu=getch();
    }
    return 0;
}

--- End code ---

stahta01:
Please DO NOT post programming questions on this SITE.
Use a programming site like http://cboard.cprogramming.com/c-programming/

Tim S.

Navigation

[0] Message Index

Go to full version