0

I have a really quick and simple question. I'm trying to make a calculator and when the user completes his equation the program asks if he wants to keep on going or he wants to exit the program. I tried to do a do-while loop but it doesn't work for some reason. Can someone help me out? Thanks

}
int main() {
    char ch;
    int A;
    do{
    printf("Vali millist tehet soovid teha:\n\n");
    printf("Liitmine - 1\nLahutamine - 2\nKorrutamine - 3\nJagamine - 4\n");
    printf("Arvu ruuduks tegemine (x2) - 5\nArvu ruut valitud eksponendiga (xy) - 6\n");
    printf("Arvu ruutjuur - 7\nArvu siinus - 8\nArvu koosinus - 9\nArvu tangens - 10\n\n");
    scanf("%d", &A);
    if (A == 1) {
        liitmine();
    }
    else if (A == 2){
        lahutamine();
    }
    else if (A == 3){
        korrutamine();
    }
    else if (A == 4){
        jagamine();
    }
    else if (A == 5){
        x2();
    }
    else if (A == 6){
        xy();
    }
    else if (A == 7){
        ruutjuur();
    }
    else if (A == 8){
        sin();
    }
    else if (A == 9){
        cos();
    }
    else if (A == 10){
        tan();
    }
    printf("\nUue tehte sooritamiseks kirjuta Y, väljumiseks kirjuta N.\n");
    scanf("%c", &ch);
    getch();
}
    while(ch == 'y' || ch == 'Y');

}
lembit
  • 1
  • 1
  • You should use `scanf(" %c", &ch);` instead of `scanf("%c", &ch);` (add space before `%c` to have `scanf()` ignore whitespace characters (including newline character). – MikeCAT Apr 23 '21 at 13:27
  • Wow! Thank you I didn't realize that a space was needed there. – lembit Apr 23 '21 at 13:33
  • See [this C reference](https://en.cppreference.com/w/c). You need to read the documentation of every function you did not define. Compile with [GCC](http://gcc.gnu.org/) invoked as `gcc -Wall -Wextra -g`. Read the documentation of your compiler and of your debugger (e.g. [GDB](https://www.gnu.org/software/gdb/)...) **StackOverflow is *not* a do-my-homework service** – Basile Starynkevitch Apr 23 '21 at 13:39

0 Answers0