Jump to content
View in the app

A better way to browse. Learn more.

Next

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[C++] Menu qui entre dans une boucle infinie.

Featured Replies

Posted

Bonjour!

Je tente de réaliser un programme pour mon cours d'info et j'ai un petit soucis. J'aimerais faire un menu tout ce qu'il y a de plus simple.

Au départ, j'avais ceci:

Le problème : ça cycle si on rentre un char (ex : a)

double test;
do
{
       cout << "Voulez-vous commencer?" << endl
            << "1- Oui." << endl << "2- Non." << endl;
       cin >> test;

} while (commencer != 1 && commencer != 2);

J'ai tenté de modifier, maintenant j'ai ça:

int commencer;
   char menu; 

   do
   {
       cout << "Voulez-vous commencer?" << endl
            << "1- Oui." << endl << "2- Non." << endl;
       cin >> menu;

       commencer=(menu-'0'); 

   } while (commencer != 1 && commencer != 2);

On peut rentrer ce qu'on veut, mais un seul caractère! Est-ce qu'il serait possible que lorsque je tape : aa, le programme considère qu'il s'agit d'un seul caractère et pas de deux.

En fait il garde le deuxième pour le prochain cin j'ai l'impression.

Merci de votre aide :)

En c, le système garde un buffer d'entrée (stdin).

Si tu ne lis que le premier caractère, le reste de la saisie y est stocké.

Pour éviter ce problème, il faut réaliser un fflush( stdin) afin de vider le buffer d'entrée.

Après, je te laisse chercher comment ça se fait en C++, sinon tu vas oublier pour ton prochain partiel ;-)

  • Author

Merci bien, je vais aller regarder si je trouve quelque chose à ce niveau là :) .

Archived

This topic is now archived and is closed to further replies.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.