wiederhollung



  • hi

    hätte eine kurze frage an euch undzwar

    hab ich hier einen code

    #include <iostream>
       #include <vector>
       #include <conio.h>
       using namespace std;
    
       int main(int argc, char *argv[]) 
    {
    
       vector <string> texte;
       cout<< "" << endl;
       texte.push_back("1");
       texte.push_back("2");
       texte.push_back("3");
       texte.push_back("4");
       texte.push_back("5");
       texte.push_back("5");
    
           cout<<texte[rand()%texte.size()]<<endl;
    
    getch();
    

    und jetzt würde ich gerne machen so das wenn ich z.b 1 drücke die wiederhollung noch mal anfängt und bei 2 die console sich schliesst

    danke schon mal im vorraus für jede hilfe 🙂



  • #include <iostream>
    #include <vector>
    #include <conio.h>
    using namespace std;
    
    int main(int argc, char *argv[])
    {
      char c = '1';
      while( c == '1' )
      {
        vector <string> texte;
        cout<< "" << endl;
        texte.push_back("1");
        texte.push_back("2");
        texte.push_back("3");
        texte.push_back("4");
        texte.push_back("5");
        texte.push_back("5");
    
        cout<<texte[rand()%texte.size()]<<endl;
    
        cin >> c;
      }
      return 0;
    }
    

    so etwa?

    //edit: wenn du direkt auf tastendruck weitermachen (nochmal schleife durchlaufen / beenden) willst, geht das glaube ich mit _getch(), aber das habe ich auch noch nie benutzt.

    mfg,
    julian


Anmelden zum Antworten