adblock check

(RU) Пожалуйста вот мой 1 проект, Сделал её 2 дня ВНИМАНИЕ тут только дробные числа подходит вот так (22.2) запускаем ярлык всё.

исходный код:

если что могут баги и ошбки

if anything, there may be bugs and errors.

(EN) Please, here is my 1 project, I did it for 2 days. ATTENTION, only fractional numbers are suitable here, so (22.2) we run the shortcut all. the source code:

Вышла новая версия 0.2 с улучшениями кода

над ней работал целую неделю

и тип Дабал спасибо Егору или Limows

за улучшения кода.

И я тоже улучл код

потом сделаю версию на русском языке

Системные требования

OS WIN 11/10 (64X)

MS V C ++ 2022

ОЗУ 2 ГБ

FOR ДЛЯ 0.1

#include <iostream>

int main()

{

float num1, num2,res;

std::cout << «enter num1: »;

std::cin >> num1;

std::cout << «enter num2: »;

std::cin >> num2;

char math;

std::cout << «enter math symbol: »;

std::cin >> math;

if (math == '+')

res = num1 + num2;

else if (math == '-')

res = num1 — num2;

else if (math == '*')

res = num1 * num2;

else if (math == '/')

res = num1 / num2;

std::cout << «result: » << res;

return 0;

}

FOR 0.2

#include <limits>

#include <iostream>

int main()

{

double num1, num2, res;

char math;

std::cout << «enter num1: »;

while (!(std::cin >> num1)) {

std::cin.clear();

std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');

}

std::cout << «enter num2: »;

while (!(std::cin >> num2)) {

std::cin.clear();

std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');

std::cout << «Invalid input. Enter a number: »;

}

std::cout << «enter math symbol (+, -, *, /): »;

while (!(std::cin >> math) || (math != '+' && math != '-' && math != '*' && math != '/')) {

std::cin.clear();

std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');

std::cout << «Invalid operator. Enter +, -, *, or /: »;

}

switch (math) {

case '+':

res = num1 + num2;

break;

case '-':

res = num1 — num2;

break;

case '*':

res = num1 * num2;

break;

case '/':

if (num2 == 0.0) {

std::cout << «Error: Division by zero!» << std::endl;

return 1;

}

res = num1 / num2;

break;

default:

std::cout << «Error: Invalid operator!» << std::endl;

return 1;

}

std::cout << «Result: » << res << std::endl;

return 0;

}

M2000 M2000
Пользователь
Ryzen 5 3500U / Radeon Vega 8🇷🇺
1 комментарий
Оставьте комментарий...
Оставьте комментарий...
Ееее калькулятор