Hey guys,
I've tried to write a quite simple programm, a dictionary for me and my classmates, where you enter the word you don`t know and get the definition of it.
I keep getting the error: "expected unqualified-id before '{' token" and "expected initializer before 'string'.
I`ve already managed to run the programm with just one entry but since I included the switch function and more entrys, I`m getting this errors.
I tried changing things a bit and looked it up in a few books but I coudn`t find the fault.
I hope you can help me. Thank you!
Ichmagkekse
.#include <iostream>
#include <cmath>
using std::cout;
using std::cin;
usingnamespace std;
int main(int argc, char* args[] )
string choice;
{
cout << "Geben sie das Fachwort ein";
cin >> choice;
string assimilation = "Assimilation: ";
string definitionassimilation = "Etwas Neues wird in ein bereits vorhandenes Schema eingeteilt";
string ausgabe; //Strings werden deklariert
string akkomodation = "Akkomodation: ";
string definitionakkomodation = "Etwas passt in kein Schema weswegen ein neues erstellt wird oder ein vorhandenes Schema wir angepasst bzw erweitert";
switch (assimilation = "Assimilation: ");
switch (definitionassimilation = "Etwas Neues wird in ein bereits vorhandenes Schema eingeteilt");
switch (ausgabe); //Strings werden deklariert
switch (akkomodation = "Akkomodation: ");
switch (definitionakkomodation = "Etwas passt in kein Schema weswegen ein neues erstellt wird oder ein vorhandenes Schema wir angepasst bzw erweitert");
{
case"assimialtion":
:ausgabe = assimilation + " " + definitionassimilation + "!"; //Strings werden verknüpft
cout << ausgabe << endl; //Fachwort und Definition werden angezeigt
case"akkomodation":
:ausgabe = akkomodation + " " + definitionakkomodation + "!"; //Strings werden verknüpft
cout << ausgabe << endl; //Fachwort und Definition werden angezeigt
default:
cout << "Entweder das Wort befindet sich nicht in unserer Datenbank oder es wurde falsch geschrieben.";
return 0;
}
}
switch (expression)
{
case constant1:
group-of-statements-1;
break;
case constant2:
group-of-statements-2;
break;
.
.
.
default:
default-group-of-statements
}
The code on line 8 should go after the beginning brace for main on line 9.
Line 1 - might just be from copying and pasting into the forum, but there's a stray period at the beginning of the line that would need to be removed if it's actually in the code.
Thank you really much for your reply, i checked the tutorial but I couldn`t find a solution how to use strings in a swith case and neither do I in my books.
Could you tell me how to do it or where to find the informations to do it?
The first space in line one is not in the code it`s just in the forum.
Thanks,
Ichmagkekse
You will not find a solution because as wildblue said you cannot use strings.
The expression used in a switch statement must have an integral or enumerated type, or be of a class type in which the class has a single conversion function to an integral or enumerated type.