Informatiker Board (http://www.informatikerboard.de/board/index.php)
- Themengebiete (http://www.informatikerboard.de/board/board.php?boardid=1)
-- Theoretische Informatik (http://www.informatikerboard.de/board/board.php?boardid=5)
--- switch-Verzweigung (http://www.informatikerboard.de/board/thread.php?threadid=1114)


Geschrieben von Weihnachtsmann24 am 25.12.2011 um 14:17:

  switch-Verzweigung

Hallo, ich lerne gerade die Programmiersprache C. So habe ich ein Problem bei einem Programm, in welchem ich versuche, die "switch-Verzweigung" einzubringen:
Zitat:

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
int b;

printf("Gib hier bitte eine Zahl ein : ");
scanf("%d", &b);
fflush(stdin);

switch(b)
{
case b<=10:
int z=b*b;
printf("%d\n", z);
break;
case b>10 && b<=20 :
float q=b*b/3;
printf("%f\n", q);
break;
case b>20 :
float u=b*b*(b/222)-22;
printf("%f\n", u);
case Nr>30 :
float l=b/5+2.5;
printf("%f\n", l);
}



system("PAUSE");
return 0;
}

Mein Compiler gibt mir für Zeile 14 diese Fehlermeldung aus:
case label does not reduce to an integer constant

Was ist daran falsch?

und zusätzlich sagt er noch zu Zeile 15:

syntax error before "int"

was stimmt hier nicht?




Vielen Dank im Voraus.



Geschrieben von Karlito am 25.12.2011 um 15:02:

 

Hallöchen,

die Switch-Verzweigung funktioniert nicht mit Bedingungen hinter dem case-Schlüsselwort.

An der Stelle darf nur eine Konstante stehen. Siehe http://www.peacesoftware.de/ckurs7.html

VG,

Karlito


Forensoftware: Burning Board, entwickelt von WoltLab GmbH