Basic calculator program in C++

This is a discussion on Basic calculator program in C++ within the C++ Programming forums, part of the General Programming Boards category; you need to do this then c = (int)x%(int)y; //cast the other two vars as ints mod won't work for ...

  1. #61
    Registered User ~Kyo~'s Avatar
    Join Date
    Jun 2004
    Posts
    320
    you need to do this then

    c = (int)x%(int)y; //cast the other two vars as ints mod won't work for floats

  2. #62
    Registered User
    Join Date
    Aug 2005
    Posts
    91
    K, it works now. Just need to allow the user to access the function in the first place. Unfortunately, it's giving me an "undeclared" error. *yawn*

    EDIT: Hah, its reason for being undeclared was that modulus isn't a legal function name (or so my observations tell me). With my previous plus() and minus() functions, it was probably the same problem!

  3. #63
    Registered User ~Kyo~'s Avatar
    Join Date
    Jun 2004
    Posts
    320
    O yea you cant do that lol... Use things like MyModulus :P

  4. #64
    Registered User
    Join Date
    Aug 2005
    Posts
    91
    I'm just calling it mod(). I'm just gonna assimilate mod() into the division half of diviminus() so that it outputs both the result of division and the remainder, and then I'll be pretty much done with the calculator.

  5. #65
    Registered User ~Kyo~'s Avatar
    Join Date
    Jun 2004
    Posts
    320
    Sounds good to me. I noticed you fixed the double entrys at some point. Forgot to mention that.

  6. #66
    Registered User
    Join Date
    Aug 2005
    Posts
    91
    Double entries? *confused*

  7. #67
    Registered User ~Kyo~'s Avatar
    Join Date
    Jun 2004
    Posts
    320
    A while back you had to enter y twice to get into the function :P guess it was longer ago than I thought lol.

  8. #68
    Registered User
    Join Date
    Aug 2005
    Posts
    91
    Oh, yeah. I mentioned that earlier, and said it had to do wit haccedentally calling "cin" twice.

    Speaking of bugs, I have a minor but weird one on in the text-based game I'm writing. It's on another topic if you want to take a look.

  9. #69
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    you need to do this then

    c = (int)x%(int)y;
    That will result in loss of precision. If you don't want that, include <math.h> and use the fmod() function. It takes two double [floating-point] arguments and moduluses them.

    Code:
    #include <math.h>
    
    printf("%lf", fmod(10.0, 8.2));
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  10. #70
    Registered User
    Join Date
    Aug 2005
    Posts
    91
    You mean <cmath> and cout, right? THis is the C++ part of the board. Thanks, though. ^_^ (if you can't tell, ^_^ is a smiley).

    EDIT: Hey, that works pretty well! I just implemented it.
    Last edited by linkofazeroth; 08-28-2005 at 04:19 PM.

  11. #71
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    Sorry, and you're welcome.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Page 5 of 5 FirstFirst 12345
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. [ANN] New script engine (Basic sintax)
    By MKTMK in forum C++ Programming
    Replies: 1
    Last Post: 11-01-2005, 09:28 AM
  2. what are your thoughts on visual basic?
    By orion- in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 09-22-2005, 04:28 AM
  3. visual basic vs C or C++
    By FOOTOO in forum Windows Programming
    Replies: 5
    Last Post: 02-06-2005, 07:41 PM
  4. Basic Window Creation, Dev C++ 4.9.9.0 Linking Error
    By Tronic in forum Windows Programming
    Replies: 2
    Last Post: 11-27-2004, 05:03 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21