-5

i try to set up Visual Studio Code, on my windows computer it seems to work Now, on Mac the code is not running completely through.

it just stops after if(speed3>0)printf("Pech gehabt!\\n");

everything after that is not shown in Terminal and i get return 0


#include <stdio.h>

int main()
{
int speed1,speed2,speed3;
double dAbzug;
char cTaste;

    printf("\n");
    printf("Wie schnell sind sie gefahren?\n");
    scanf("%d",&speed2);
    
    printf("Wie schnell war erlaubt?\n");
    scanf("%d",&speed1);
    
    printf("War die Messung (i)nnerorts oder (a)userorts?\n");
    
    fflush(stdin);
    
    scanf("%c",&cTaste);
    scanf("%c",&cTaste);
    
    
    if(speed2<=100)
    {
        dAbzug=3;
        speed2=speed2-dAbzug;
    }
    if(speed2>100)
    {
        dAbzug=speed2*.03;
        speed2=speed2-dAbzug;
    }
    
    
    
    printf("%.1lf Km/h werden abgezogen\n",dAbzug);
    
    speed3=speed2-speed1;
    
    if(speed3>0)printf("Pech gehabt!\n");
    
    if(cTaste=='I'||cTaste=='i')
    {
        if(speed3>0&&speed3<=10)printf("Macht 15 Euronen und 0 Pünktchen in Flensburg + 0 Monate laufen");
    
        if(speed3<=0)printf("Dann kannst du dich glücklich schätzen.");
    }
    
    if(cTaste=='A'||cTaste=='a')
    {
        
        if(speed3>0&&speed3<=10)printf("Macht 10 Euronen und 0 Pünktchen in Flensburg + 0 Monate laufen");
        
        if(speed3<=0)printf("Dann kannst du dich glücklich schätzen.");
    }
    printf("\n");
    
    return 0;

}
πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190
  • 2
    [`fflush(stdin)` is undefined behaviour](https://stackoverflow.com/q/2979209). – Siguza Aug 26 '23 at 16:45
  • 1
    Passing an input-only stream to `fflush` (like for example `stdin`) is explicitly mentioned in the C specification as leading to *undefined behavior*. – Some programmer dude Aug 26 '23 at 16:46
  • Besides that, have you tried to use a [*debugger*](https://stackoverflow.com/questions/25385173/what-is-a-debugger-and-how-can-it-help-me-diagnose-problems) to step through your code line by line to see what happens? For this it helps if you put different statements on separate lines. – Some programmer dude Aug 26 '23 at 16:47
  • It is a quite clear symptom of undefined behaviour – 0___________ Aug 26 '23 at 16:55
  • Siguza's link goes on to explain that it just so happens to be implemented consistently on windows and linux, but is not part of posix. Looks like osx is another system where it is not implemented. – erik258 Aug 26 '23 at 17:04
  • `scanf("%c",&cTaste);` is used twice? Is that because end-of-line is two characters on Windows but only one on Linux? – BoP Aug 26 '23 at 17:36

0 Answers0