Note that there are some explanatory texts on larger screens.

plurals
  1. POCode for a HP-35 calculator basic functions
    text
    copied!<p>Hi I am having some trouble implementing basic functions for a calculator of type HP-35 I am a beginner and I am having a lot of trouble with putting code together, the basic functions are the Addition, Subtraction, Multiplication and Division that I need help with.</p> <p>Below is my main file:</p> <pre><code>/* * File: main.cpp * Author: Brenton * * Created on 20 September 2013, 12:10 AM */ #include &lt;cstdlib&gt; #include "HPStack.h" #include &lt;iostream&gt; #include &lt;sstream&gt; using namespace std; /* * */ int main(int argc, char** argv) { HPStack stack; string line; while (getline(cin, line)) { stringstream expression(line); string token; while (expression &gt;&gt; token) { if (isdigit(token[0])) { stack.push(atof(token.data())); //From here I am having trouble, I don't know what the code is. } else if (token == "+") { // Addition code } else if (token == "-") { // Subtraction code } else if (token == "/") { // Division code } else if (token == "*") { // Multiplication code double x = stack.pop(); double y = stack.pop(); stack.push(y + x); } } cout &lt;&lt; stack.peek(); } return 0; } </code></pre> <p>Below is the code so far for the stack that I've created:</p> <pre><code>/* * File: HPStack.cpp * Author: Brenton * * Created on 20 September 2013, 12:07 AM */ #include "HPStack.h" HPStack::HPStack() { } HPStack::HPStack(const HPStack&amp; orig) { } HPStack::~HPStack() { } </code></pre> <p>Below is my code for the header file:</p> <pre><code>/* * File: HPStack.h * Author: Brenton * * Created on 20 September 2013, 12:10 AM */ #ifndef HPSTACK_H #define HPSTACK_H class HPStack { public: HPStack(); void push(double); double pop(); private: double stack; double x, y, z, t; }; #endif /* HPSTACK_H */ </code></pre> <p>I know that this seems like a dumb question to be asking, but I really haven't got a clue what I'm really doing with the mathematics code, but I'm trying. Any help would be greatly appreciated</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload