0

I'm making a calculator based on the library and I wanted to implement powers, however my code seems to completely skip the powering process and I have no idea why.

The code below is a fraction of my code and I hope that is enough for possible advices and help.

float Kalkulator::mnozenie()
{
    float wynik;
    if (ObecnElem == "(")
    {
        nastepny();                                                 
        wynik = dodawanie();
        nastepny();
    }
    else
    {
        wynik = intZmiana(ObecnElem);
        nastepny();
    }
    return wynik;
}

void Kalkulator::nastepny()
{    
    listElem.pop_front();
    if (!listElem.empty())
    {
        ObecnElem = listElem.front();           
    }
    else
    {
        ObecnElem = string();
    }
}

float Kalkulator::potegowanie()
{
    float wynik = mnozenie();
    while (ObecnElem == "^")
    {
        if (ObecnElem == "^")
        {
            nastepny();
            float p = pow(wynik, mnozenie());
            wynik = p;                                                                    

            cout << "\n";
            cout << wynik;
            copy(begin(listElem), end(listElem), ostream_iterator<string>(cout, ""));
            cout << "\n";
        }
    }
    return wynik;
}
Amadeusz
  • 1
  • 1
  • You'll be glad to hear you don't need anyone's help to figure this out, just a tool you already have: your debugger! This is exactly what a debugger is for. It [runs your program, one line at a time, and shows you what's happening](https://stackoverflow.com/questions/25385173/), this is something that's every C++ developer must know how to do. With your debugger's help you'll able to quickly find all problems in this and all future programs you write, without having to ask anyone for help. Have you tried using your debugger, already? If not, why not? What did your debugger show you? – Sam Varshavchik Jan 22 '22 at 20:21
  • 1
    I have no idea the flow of any of this code. 1) The code uses non-English variable and function names and 2) There is no `main` function that calls anything with appropriate data that duplicates the issue. – PaulMcKenzie Jan 22 '22 at 20:23
  • @SamVarshavchik Aah I'm sorry, I have never used a debugger before, I'm really only beginning to code and the task I received, being a wolfram-like calculator in c++ has really made me struggle. I will definitely try using it and hopefully find the correct solution, Thank you a lot and have a nice day :D – Amadeusz Jan 22 '22 at 20:25
  • @PaulMcKenzie Yes, I am aware of that, this post might as well be called an outburst of my desperation in fixing my issue. I'm sorry for wasting your time. – Amadeusz Jan 22 '22 at 20:26
  • This sounds like a way too complicated task for someone who's "only beginning to code". What exactly is the topic of the chapter in the textbook, where this practice problem is from? Perhaps you're misunderstanding it and you should be doing something much simpler? – Sam Varshavchik Jan 22 '22 at 20:31
  • @SamVarshavchik Our teacher told us that our project for this semester will be writing a calculator showing steps made in achieving your final value(C++). He said he will be comparing our program to WolframAlpha. The resources discussed on our lectures and lessons were basically "how to write a class-based program" and nothing was ever said about reverse polish notation, shunting yard algorithm, stack method or even basic libraries. I felt helpless a lot of times, but again I understand that's none of anyones business and I'm sorry for taking your time. Hope you have a great day! – Amadeusz Jan 22 '22 at 21:19
  • That's quite all right, you aren't the first one to bring forward evidence of an incompetent C++ instructor. There's a lot of them. Unfortunately, Stackoverflow is not a replacement for a C++ textbook, and we're not a tutorial. Maybe you can get some help if you make your question more clear. A complete stranger, who walks of the street, which we all are, really won't have any idea what "seems to completely skip the powering process and I have no idea why" actually means. – Sam Varshavchik Jan 22 '22 at 23:04
  • @Amadeusz -- I have seen teachers work in the way you described. The reason why they do this is to have students that will not be good programmers drop out of the course, and only the 3 or 4 that are left will ever complete the assignment. It's a test to see how much of an independent study person you are. You mentioned "shunting yard" and other things, and maybe that's the whole idea -- for you to find these things out yourself and present it to the teacher. And of course, the other side of it could be that the teacher is incompetent, but who knows? – PaulMcKenzie Jan 23 '22 at 22:21

0 Answers0