ich bin ganz neu hier im Forum und brauche einen Rat von euch.
Ich habe das Problem das bei meiner Switch Case Anweisung das Multiplikationszeichen nicht erkannt wir und dafür dann der default Block ausgeführt wird.
Die anderen Operationszeichen funktionieren.
Was kann das Problem sein?
Vielen Dank für jegliche Hilfe.
Hier der Code:
Code: Alles auswählen
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <assert.h>
main(int argc, char *argv[])
{
double x, y, z;
if(argc < 4){
printf("\nAufruf: %s zahl1 op zahl2",argv[0]);
exit(1);
}
x=atof(argv[1]);
y=atof(argv[3]);
switch(argv[2][0]){
case '+':
z=x+y;
break;
case '-':
z=x-y;
break;
case '*':
z=x*y;
break;
case '/':
z=x/y;
break;
default:
printf("\n Falsches Operationszeichen!");
exit(2);
}
printf("%s %s %s = %.2f\n",argv[1],argv[2],argv[3],z);
system("PAUSE");
return 0;
}