Compare commits

...

3 Commits

Author SHA1 Message Date
481de18bbd fix: do calcul in right order 2023-12-16 12:19:37 +01:00
a37a07615b ex00: fix valid date 2023-12-16 12:19:09 +01:00
9965c6d49d ex01: clean remove trash file 2023-12-16 12:18:58 +01:00
3 changed files with 10 additions and 13 deletions

View File

@ -21,7 +21,6 @@ static bool is_leap(int year)
static bool date_is_valid(int d, int m, int y)
{
return false;
if (m < 1 || m > 12)
return false;
if (d < 1 || d > 31)

View File

@ -1,4 +0,0 @@
#include <stack>
#include <iostream>

View File

@ -16,10 +16,10 @@ int calculate(std::stack<int>& nums, std::stack<char>& operators)
return 0;
int ret;
int a = nums.top();
nums.pop();
int b = nums.top();
nums.pop();
int a = nums.top();
nums.pop();
switch (operators.top()) {
case '+':
@ -60,17 +60,19 @@ int main(int ac, char** av)
if (std::isdigit(av[1][i]))
nums.push(av[1][i] - '0');
else if (std::strchr("/+-*", av[1][i]) != NULL)
{
operators.push(av[1][i]);
if (calculate(nums, operators))
{
std::cout << "error: division by 0" << std::endl;
return 1;
}
}
else
{
std::cout << "error: '" << av[1][i] << "' unknown char" << std::endl;
return 1;
}
if (calculate(nums, operators))
{
std::cout << "error: division by 0" << std::endl;
return 1;
}
}
if (nums.size() != 1)
{
@ -79,7 +81,7 @@ int main(int ac, char** av)
}
if (operators.size() != 0)
{
std::cout << "error: too manu operators" << std::endl;
std::cout << "error: too many operators" << std::endl;
return 1;
}
std::cout << nums.top();