calculator
#include <stdio.h>
#include<stdlib.h> //заголовний файл в якому міститься операнд очищення консолі
#include "header.h"
int main() {
double number;
double second_number;
char operation;
reset: //мітка для переходу після введення команди скидання
//виведення тексту
printf("List of aviable operations and their 'commands': \n\n'+'\t '-'\t\t '/'\t '*'\t\t'e'");
printf("\nadd\tsubstract\tdivide\tmultiply\texit");
printf("\n\n's'\t 'm'\t\t 'r'\t 'c'");
printf("\nsin(x)\t |x|\t\tsqrt(x)\tclear");
printf("\n\n(for sine the number must be entered in degrees, for squre root the number must be positive)\n\n");
//введення першого числа і запобігання введення невірних даних
printf("Enter first number: ");
scanf("%lf", &number);
operation: //мітка для переходу до наступної операції
//введення команди операції
printf("Enter operation command:");
scanf(" %c", &operation);
//перевірка на коректність команди операції
if (correct_check(operation) == -1) {
printf("\nEntered incorrect operation command\n");
return -1;
}
//перевірка на потребу введення другого числа
if (operation != 's' && operation != 'm' && operation != 'r' && operation != 'c' && operation != 'e') {
//введення другого числа і запобігання введення невірних даних
printf("Enter second number: ");
scanf("%lf", &second_number);
}
//розгалудження на операції
switch (operation)
{
case '+':
number = number + second_number;
break;
case '-':
number = number - second_number;
break;
case '/':
number = number / second_number;
break;
case '*':
number = number * second_number;
break;
case 's':
number = sinx(number);
break;
case 'm':
number = modulex(number);
break;
case 'r':
if ((sqrtx(number)) == -1) {
printf("impossible to find the square root of a negative number\n");
return -1;
}
else number = sqrtx(number);
break;
case 'c':
//операція скидання, переход на початок коду
system("cls");
goto reset;
case 'e':
return 0;
}
//виведення проміжного результату
printf("\nYour result is %lf", number);
printf("\nDo you want to continue?\nenter 'y' if yes \nenter 'n' if no\n");
scanf(" %c", &operation);
if (operation == 'y') goto operation;
else return 0;
}INFO