Author Topic: variables problem ! (please help a noob)  (Read 2631 times)

bingofuel

  • Guest
variables problem ! (please help a noob)
« on: March 05, 2011, 05:18:14 am »
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;

}

thlgood

  • Guest
Re: variables problem ! (please help a noob)
« Reply #1 on: March 05, 2011, 06:03:04 am »
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;
}
Code
#include <stdio.h>
#include <conio.h>
int main()
{
    char menu=0;
    while (menu !='r')
    {
        printf("error\n");
        menu=getch();
    }
    return 0;
}


Offline stahta01

  • Lives here!
  • ****
  • Posts: 7588
    • My Best Post
Re: variables problem ! (please help a noob)
« Reply #2 on: March 05, 2011, 06:36:15 am »
Please DO NOT post programming questions on this SITE.
Use a programming site like http://cboard.cprogramming.com/c-programming/

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org