CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: help letter k

  1. #1
    Join Date
    Apr 2015
    Posts
    1

    Unhappy help letter k

    Hello world im french and i must write code to find letter k with 10 drops + or -

    #include <iostream>
    #include <stdlib.h>

    using namespace std;

    int main()

    {
    char caractere='k';
    int essai=0;

    do

    {
    cout << " Tapez une lettre au clavier"<< endl;
    cout << " Vous avez 10 essais pour trouver la lettre mystere."<< endl;
    cin >> caractere ;

    essai=essai+1; // incrementation du nombre d'essai
    }


    if (caractere=='k') // test de condition
    {

    cout << " bravo vous avez trouvez la bonne lettre " << endl ;
    cout << " Vous avez eu besoin de " << essai << " essai pour trouver la lettre mystere " << endl ;

    }
    if(caractere !='k')

    {
    cout << "Plus !" << endl;
    }

    else
    {

    cout << " Moins !" << endl;
    }

    while (caractere=='k'); // boucle tant que le joueur ne trouve pas la lettre mystere


    return 0;

    system ("PAUSE" );



    }

  2. #2
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,825

    Re: help letter k

    When posting code, please use code tags. Go Advanced, select the formatted code and click '#'.

    Code:
    essai=essai+1; // incrementation du nombre d'essai
    }
    shouldn't the closing brace go with the while part of the do loop?

    You are incrementing essai but not testing to see if 10 or more entries have been tried. Shouldn't this test be part of the while clause?

    If you have to loop until a 'k' is entered, your while condition doesn't seem correct?

    Also you are describing an entry that is not a 'k' as greater and an entry that is a 'k' as less?? Shouldn't the condition be > for Plus and < for Moins?
    Last edited by 2kaud; April 2nd, 2015 at 07:00 AM.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured