I wrote a program, I want a dot or comma to appear as a separator and an integer separator (at the moment when entering fractions separated by commas, for example, 2.1 the program closes CODE
#include <stdio.h> #include <math.h> #include <assert.h> #include <windows.h> #include <iostream> #include <locale> int tok; double tokval; int next() { for (;;) { int c = getchar(); if (c == EOF || strchr("+-*/^()\n", c) != NULL) return tok = c; if (isspace(c)) continue; if (isdigit(c) || c == '.') { ungetc(c, stdin); scanf(" %lf", &tokval); return tok = 'n'; } fprintf(stderr, "Bad character: %c\n", c); abort(); } } void skip(int t) { assert(tok == t); next(); } double expr(); double numpar() { if (tok == 'n') { double x = tokval; skip('n'); return x; } skip('('); double x = expr(); skip(')'); return x; } double factor() { double x = numpar(); if (tok == '^') { skip('^'); x = pow(x, factor()); } return x; } void exit() { } double term() { double x = factor(); for (;;) { if (tok == '*') { skip('*'); x *= factor(); } else if (tok == '/') { skip('/'); x /= factor(); } else return x; } } double expr() { double x = term(); for (;;) { if (tok == '+') { skip('+'); x += term(); } else if (tok == '-') { skip('-'); x -= term(); } else return x; } } int main() { SetConsoleCP(1251); SetConsoleOutputCP(1251); printf("ΠΠ½ΡΠΎΡΠΌΠ°ΡΠΈΡ:\n(*)ΡΠΌΠ½ΠΎΠΆΠ΅Π½ΠΈΠ΅, (+)ΡΠ»ΠΎΠΆΠ΅Π½ΠΈΠ΅, (-)Π²ΡΡΠΈΡΠ°Π½ΠΈΠ΅, (/)Π΄Π΅Π»Π΅Π½ΠΈΠ΅, (^)Π²ΠΎΠ·Π²Π΅Π΄Π΅Π½ΠΈΠ΅ Π² ΡΡΠ΅ΠΏΠ΅Π½Ρ\nΠΡΠΈ ΠΈΡΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°Π½ΠΈΠΈ Π½Π΅ ΡΠ΅Π»ΡΡ
ΡΠΈΡΠ΅Π» ΠΏΠΎΠ»ΡΠ·ΡΠΉΡΠ΅ΡΡ ΡΠΈΠΌΠ²ΠΎΠ»ΠΎΠΌ (.)\n"); printf("ΠΠ²Π΅Π΄ΠΈΡΠ΅ Π²ΡΡΠ°ΠΆΠ΅Π½ΠΈΠ΅:\n"); next(); while (tok != EOF) { if (tok == '\n') { skip('\n'); continue; } printf("Π Π΅Π·ΡΠ»ΡΡΠ°Ρ:%.9g\n", expr()); } return 0; }
scanf()- avp