Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Starting C++, calculator

Name: Anonymous 2007-04-18 5:18 ID:cwaeIkIV

In c++. Every calculator I have seen is just like "enter two numbers to have them added" I want it to just keep giving me the option to keep adding (or whatever operation i choose) numbers until i want it to stop.

Name: Anonymous 2007-04-18 5:23 ID:Heaven

Write a parser for it you dumb fuck.

Name: Anonymous 2007-04-18 5:30 ID:L3e9MWwU

Use RPN.

Name: Anonymous 2007-04-18 6:27 ID:cwaeIkIV

what is a parser, and what is RPN. I just want help with a simple calculator. Thanks

Name: Anonymous 2007-04-18 6:31 ID:Heaven

>>4
Use Google.

Name: Anonymous 2007-04-18 6:35 ID:Heaven

>>4
fail, do you realize this is EXPERT PROGRAMMERS AREA and you are asking for a calculator?
Plus, if one wants to write a calculator, one must first know the basics of the language he uses.
I bet you don't even know half of the basics of C++

Name: Anonymous 2007-04-18 6:41 ID:Heaven


int calc(char *math) {
    char *p;
    int a, b;
    if((p=index(math,'+'))==NULL) exit(-1) // fag
    a = atoi(math);
    b = atoi(p+1);
    return a + b;
}
   
int main() {
   
    char shiz[40];
    int lolwut = 0;
    while(1) {
        cout << "Enter your shiz: ";
        cin >> shiz;
        lolwut += calc(shiz);
        cout << "Answer iz " << lolwut += calc(shiz) << endl;
    }
   
   
}

Name: Anonymous 2007-04-18 6:42 ID:h/qxMvZb

Or even better..

int calc(char *math) {
return atoi(math) + atoi(index(math,'+')+1);
}

Name: Anonymous 2009-01-14 14:41

I AM AN EXPERT PROGRAMMER

Name: Anonymous 2009-03-06 7:29


I bet Richard Stallman   If you are   a hypocrite anyway   Read the god   that is EMACS   does LEAVE NOW.

Name: Anonymous 2010-11-02 11:05

Name: Anonymous 2010-12-06 9:35

Back to /b/, ``GNAA Faggot''

Name: Sgt.Kabu䌁䧿kiman跷⁙ 2012-05-29 0:19

Bringing /prog/ back to its people
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy

Don't change these.
Name: Email:
Entire Thread Thread List