Dictionary with swich statment and string

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





1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
.#include <iostream>
#include <cmath>
using std::cout;
using std::cin;
using namespace 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;
    }
}
Check your syntax on the switch. Also - you can't use a string as the switch case as you are here.

There's a section in the tutorial on this site - scroll down on this page to see more info http://www.cplusplus.com/doc/tutorial/control/

It should look something like this.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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.


http://www.tutorialspoint.com/cplusplus/cpp_switch_statement.htm
Topic archived. No new replies allowed.