Vokabeltrainer

02/05/2013 17:18 xNRgiZeDx™#1
Hallo,
Ich wollte einen Vokabeltrainer coden, der mir Vokabeln aus einer .txt datei ausliest. Habe das problem, dass ich bei der überprüfung immer nur das erste Wort überprüfen kann,
Code:
while(theList >> voknum >> gervok >> engvok){

    cout << voknum << " | " << engvok <<  endl;
    cin >> gervok;           // Was muss hier rein?
..
Code:
#include <iostream>
#include <fstream>
using namespace std;

int main()
{
    cout << "Willkommen im Vokabel Trainer !" << endl;
   ifstream theList("vokabeln.txt");

   int voknum;
   string gervok;
   string engvok;
   


   while(theList >> voknum >> gervok >> engvok){

    cout << voknum << " | " << engvok <<  endl;
    cin >> gervok;           // Was muss hier rein?

if(gervok == "schnee"){  // ?

     cout << " " << endl;
     cout << "Richtig!" << endl;
     cout << " " << endl;
     continue;

    }else{

        cout << " " << endl;
        cout << "Leider Falsch!" << endl;
        cout << " " << endl;
        break;

        }

if(gervok == "regen"){    // ?

    cout << " " << endl;
    cout << "Richtig!" << endl;
    cout << " " << endl;
    continue;

}else{

     cout << " " << endl;
     cout << "Leider Falsch!" << endl;
     cout << " " << endl;
     break;
}

if(gervok == "sonne"){  // ?

    cout << " " << endl;
    cout << "Richtig" << endl;
    cout << " " << endl;

}else{

    cout << "" << endl;
    cout << "Leider Falsch!" << endl;
    cout << " " << endl;
    break;

}

   }



}
02/05/2013 19:59 .SkyneT.#2
Also die Lösung von dir ist etwas... komplizierter als nötig.

Nur mal ein anderer Lösungsweg (in C und eher als Pseudocode anzusehen):

vokabeln.txt:
Code:
deutsch:englisch
foo:bar
...
...
Code:
Code:
FILE *pFile = fopen("vokabeln.txt", "r");
while (! feof(pFile))
{
   fscanf(pFile, "%s:%s", de, en); 
   //Eingabe mit en vergleichen ... Rest ist selbsterklärend...
}
02/05/2013 20:36 xNRgiZeDx™#3
Ja ich weiss nicht wie ich die Vokabeln direkt über die Textdatei überprüfen kann. Danke, code versteh ich zwar nicht so ganz da in C aber vielleicht meldet sich noch jemand.
02/05/2013 21:12 xazorstix#4
Sorry hatte überlesen das du es aus einer Datei einlesen möchtest, diese Lösung ist ohne einlesen aus einer Datei...

Du könntest auch 2 arrays nehmen:

#include <iostream>
#include <string>

int main()
{
std::string engVok[5];
std::string gerVok[5];

//Initialisieren
//z.B. gerVok[0] = "Hallo"; engVok[0] = "Hello";

cin >> engVok[0]

if(engVok[0] == gerVok[0])
cout << "richtig/right" << endl;
else
cout << "falsch/false" << endl;
}

Wenn du alle Vokabeln durchgehen willst kannst du das ganze auch noch durch ne for schleife laufen lassen...
02/05/2013 21:16 MDG2004#5
ja
02/06/2013 01:17 marykillsjane#6
Quote:
Originally Posted by xNRgiZeDx™ View Post
Hallo,
Ich wollte einen Vokabeltrainer coden, der mir Vokabeln aus einer .txt datei ausliest. Habe das problem, dass ich bei der überprüfung immer nur das erste Wort überprüfen kann,
Code:
while(theList >> voknum >> gervok >> engvok){

    cout << voknum << " | " << engvok <<  endl;
    cin >> gervok;           // Was muss hier rein?
..
Code:
#include <iostream>
#include <fstream>
using namespace std;

int main()
{
    cout << "Willkommen im Vokabel Trainer !" << endl;
   ifstream theList("vokabeln.txt");

   int voknum;
   string gervok;
   string engvok;
   


   while(theList >> voknum >> gervok >> engvok){

    cout << voknum << " | " << engvok <<  endl;
    cin >> gervok;           // Was muss hier rein?

if(gervok == "schnee"){  // ?

     cout << " " << endl;
     cout << "Richtig!" << endl;
     cout << " " << endl;
     continue;

    }else{

        cout << " " << endl;
        cout << "Leider Falsch!" << endl;
        cout << " " << endl;
        break;

        }

if(gervok == "regen"){    // ?

    cout << " " << endl;
    cout << "Richtig!" << endl;
    cout << " " << endl;
    continue;

}else{

     cout << " " << endl;
     cout << "Leider Falsch!" << endl;
     cout << " " << endl;
     break;
}

if(gervok == "sonne"){  // ?

    cout << " " << endl;
    cout << "Richtig" << endl;
    cout << " " << endl;

}else{

    cout << "" << endl;
    cout << "Leider Falsch!" << endl;
    cout << " " << endl;
    break;

}

   }



}
Code:
std::string line ;
std::ifstream theList ;
while(theList)
{
cout << voknum << " | " << engvok <<  endl;
cin >> gervok;           // Was muss hier rein?

if(gervok == "schnee"){  // ?

     cout << " " << endl;
     cout << "Richtig!" << endl;
     cout << " " << endl;
     continue;

    }else{

        cout << " " << endl;
        cout << "Leider Falsch!" << endl;
        cout << " " << endl;
        break;

        }
std::getline(theList,line)  // Dadurch springt er beim Lesen in die nächste Zeile der .txt Datei sprich du musst die Vokabeln auch Zeilenweise unternander schreiben.
}
Ich hoffe du verstehst wie ich das meine ,und ich hoffe ich habe dich auch richtig verstanden^^. Das hier könnte dir evtl helfen die getline funktion zu verstehen [Only registered and activated users can see links. Click Here To Register...]
02/06/2013 18:06 xNRgiZeDx™#7
Ja denke ich hab's verstanden, habe es dennoch so gelöst.
Code:
#include <iostream>
#include <fstream>
using namespace std;

int main()
{
    cout << "Willkommen im Vokabel Trainer !(Zum beenden einfach CtrL + Z druecken.)" << endl;
    cout << "Leerzeichen bitte mit unterstrich_ " << endl;
    cout << "" << endl;
   ifstream theList("vokabeln.txt");

   int voknum;
   string gervok;
   string engvok;
   string a;


   while(theList >> voknum >> gervok >> engvok){

    cout << voknum << " | " << gervok <<  endl;
    cin >> a;           

if(a == engvok){  

     cout << " " << endl;
     cout << "Richtig!" << endl;
     cout << " " << endl;
     continue;

    }else{

        cout << " " << endl;
        cout << "Leider Falsch!" << endl;
        cout << " " << endl;
        continue;

        }





   }



}
02/08/2013 20:19 Devil0s#8
Du kannst ja auch versuchen ne Datenbank zu nehmen (also ne Tabelle).
02/09/2013 00:19 Hacker41822#9
mary du hast ihn geholfen D:
02/09/2013 12:38 xNRgiZeDx™#10
@Devil0s Jo mal sehn ob ich das hin bekomme. Jetzt wir erst mal Karneval gefeiert ;)