stefx4 rozwiązane zadania
stefx
22.6.2021 (09:43)
#include
int main() {
char mathOp;
double numA, numB, numC;
double result;
std::cout << "Choose math operation:" << std::endl;
std::cout << "* or /" << std::endl;
std::cin >> mathOp;
switch(mathOp)
{
case '*':
std::cout << "Type first number: ";
std::cin >> numA;
std::cout << "Type second number: ";
std::cin >> numB;
std::cout << "Type third number: ";
std::cin >> numC;
if (numA == 0 || numB == 0 || numC == 0) {
std::cout << "0 * any number is allways 0";
break;
}
else {
result = numA * numB * numC;
std::cout << result;
break;
}
case '/':
std::cout << "Type first number: ";
std::cin >> numA;
std::cout << "Type second number: ";
std::cin >> numB;
if (numA == 0 || numB == 0) {
std::cout << "Can't divide by 0";
break;
}
else {
result = numA / numB;
std::cout << result;
break;
}
default:
std::cout << "Choose correct math operaton";
}
return 0;
}
Przydatne rozwiązanie?
Tak
Nie