Endlosschleife



  • Hallo Leute! Ich bin gerade dabei ein neues Programm zu schreiben. Und um wieder rein zu kommen hab ich u.a. einen Code geschrieben, dessen Auszug ich nachfolgend anhänge. Es funkt alles bis auf eins, was mir aber in diesem Falle unerklärlich ist: Diese Schleife bleibt in sich hängen und das obwohl die Schleife meiner Meinung nach wunderbar geschlossen ist (Eingabeaufforderung!) und auch der Wert mit dem er die Eingabe am Schluss vergleicht, um den Lauf zu beenden, aktualisiert wird! Aber vielleicht hab ich einfach einen Denkfehler! Freue mich auf eine baldige Antwort. Danke vorab und LG

    cin >> password;
    
    while (password != password_right)
    
    	{
    
    	cout << "Have you changed your password lately? Type '1' for Yes!" << endl;
    
    	cin >> bAnswer;
    
    	if (bAnswer == 1)
    
    		{
    
    		cout << "Please type it in and press 'Enter' to continue! To check the correctness of your new password you'll be forwarded to the Dropbox Login Page!" << endl;
    
    		cin >> password_new;
    
    		system("firefox https://www.dropbox.com/login?src=logout");
    
    		cout << "Please confirm your password!" << endl;
    
    		cin >> password_new;
    
    		cout << "Your new password will be saved!" << endl;
    
    		password_new = password_right;
    
    		cout << "Please confirm your new password again to continue" << endl;
    
    		}
    
    	else 
    		{
    
    		cout << "Your password is incorrect! Please type in your mail user (e.g. maxlindson)!" << endl;
    
    		cin >> email;
    
    		cout << "Please Wait you will be forwarded to the Dropbox Website!" << endl;
    
    		system("firefox https://www.dropbox.com/forgot?email_from_login=");
    
    		cout << "Please type in your new password!" << endl;
    
    		cin >> password_new;
    
    		cout << "Your new password will be saved!";
    
    		password_new = password_right;		
    
    		cout << "Please confirm your new password!" << endl;
    
    		}
    
    	cin >> password;
    
    	}
    
    return password;
    
    }
    
    int main()
    
    {
    
    password();
    

  • Mod



  • Welche Typen haben denn die Variablen?



  • Danke Sepp wollts eh machen habs nur vergessen! Also nachfolgend nochmal der Code in ausführbarer Version! Zur Antwort von Dirk: Es handelt sich um string Variablen!

    #include <iostream>
    #include <cstring>
    #include <string.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <pthread.h>
    
    using namespace std;
    
    string password()
    {
    
    string password;
    string password_right = "k1n9u8l8ch";
    string password_new;
    string email;
    bool bAnswer;
    
    cout << "Welcome to Dropbox Sync! This program will synchronize your Pics and Videos with your Personal directory!" << endl << "For security reasons and to confirm your decision, please type in your Dropbox password! If you don't know it anymore type it wrong and you will be forwarded to the Dropbox Website where you can reset your password and define a new one!" << endl;
    
    cin >> password;
    
    while (password != password_right)
    
    	{
    
    	cout << "Have you changed your password lately? Type '1' for Yes!" << endl;
    
    	cin >> bAnswer;
    
    	if (bAnswer == 1)
    
    		{
    
    		cout << "Please type it in and press 'Enter' to continue! To check the correctness of your new password you'll be forwarded to the Dropbox Login Page!" << endl;
    
    		cin >> password_new;
    
    		system("firefox https://www.dropbox.com/login?src=logout");
    
    		cout << "Please confirm your password!" << endl;
    
    		cin >> password_new;
    
    		cout << "Your new password will be saved!" << endl;
    
    		password_new = password_right;
    
    		cout << "Please confirm your new password again to continue" << endl;
    
    		}
    cin >> password;
    
    	}
    
    return password;
    
    }
    
    int main()
    
    {
    
    password();
    
    cout << "Hallo dies ist mein Programmbeispiel";
    system ("sleep 1.5s");
    return 0;
    }
    


  • Du wolltest wohl folgendes schreiben:

    cout << "Your new password will be saved!" << endl;
    password_right = password_new;
    

    Sonst ändert sich password_right ja nie und du hängst ewig in der Schleife.

    PS: Überleg nochmal welche deiner Header Dateien überhaupt Notwendig sind und welcher wichtige Header fehlt. Zwei Tipps: cstring und string.h sind die (fast) gleichen Header und haben beide nichts mit std::string zu tun.



  • Hallo der string email wird natürlich nicht verwendet also hier nochmal der aktualisierte Code! Leider gehts nicht viel kürzer!

    #include <iostream>
    #include <cstring>
    #include <string.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <pthread.h>
    
    using namespace std;
    
    string password()
    {
    
    string password;
    string password_right = "k1n9u8l8ch";
    string password_new;
    bool bAnswer;
    
    cout << "Welcome to Dropbox Sync! This program will synchronize your Pics and Videos with your Personal directory!" << endl << "For security reasons and to confirm your decision, please type in your Dropbox password! If you don't know it anymore type it wrong and you will be forwarded to the Dropbox Website where you can reset your password and define a new one!" << endl;
    
    cin >> password;
    
    while (password != password_right)
    
        {
    
        cout << "Have you changed your password lately? Type '1' for Yes!" << endl;
    
        cin >> bAnswer;
    
        if (bAnswer == 1)
    
            {
    
            cout << "Please type it in and press 'Enter' to continue! To check the correctness of your new password you'll be forwarded to the Dropbox Login Page!" << endl;
    
            cin >> password_new;
    
            system("firefox https://www.dropbox.com/login?src=logout");
    
            cout << "Please confirm your password!" << endl;
    
            cin >> password_new;
    
            cout << "Your new password will be saved!" << endl;
    
            password_new = password_right;
    
            cout << "Please confirm your new password again to continue" << endl;
    
            }
    cin >> password;
    
        }
    
    return password;
    
    }
    
    int main()
    
    {
    
    password();
    
    cout << "Hallo dies ist mein Programmbeispiel";
    system ("sleep 1.5s");
    return 0;
    }
    


  • Danke sebi707! Ein kleiner Flüchtigkeitsfehler mit verheerenden Folgen. Ich definiere ja sonst die Variable password_new neu mit dem alten Passwort und der ganze Prozess ist 100 % sinnlos! Danke. Und die string - Library selber hat natürlich gefehlt. Ich hatte das falsch in Erinnerung, ich dachte string.h bzw. cstring sind jene Funktionen, die die Möglichkeit mit strings zu arbeiten bereitstellen! LG


Anmelden zum Antworten