Thread: A simple calculator in C

  1. #1
    Registered User
    Join Date
    Oct 2006
    Posts
    6

    A simple calculator in C

    Could someone show me the source code to a simple calculator for the 4 basic arithmetic functions in C?

    I'm wanting to build one, but I want to see a really simple one and look over the code to see if i can enhance it. I think trying to read code samples while learning it will help me understand C a lot better.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Translation: I'm too lazy and/or stupid to write my own, so I want you to write it for me so i can "enhance it".


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Oct 2006
    Posts
    6
    No, I only wanted to see how one was made. I'll attempt one and I'll post if I need help. My apologies, if that came off wrong.

  4. #4
    and Nothing Else Matters
    Join Date
    Jul 2006
    Location
    Philippines
    Posts
    117
    does it take in multiple operands and operators at all at the same time? and use parentheses? well then, an RPN (using stack ADT) calculator is the best solution to you problem. where to find it, try google and forum search.

    and bear with quzah, he's the resident "mr. nice guy" here.
    It is not who I am inside but what I do that defines me.

  5. #5
    Registered User
    Join Date
    Oct 2006
    Posts
    6
    Thanks.

    What type of programs can you make in C? Is it mainly mathmatical programs?

  6. #6
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    You can make any kind of program in C.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  7. #7
    and Nothing Else Matters
    Join Date
    Jul 2006
    Location
    Philippines
    Posts
    117
    hey, im no expert here. but i think you can make almost any type of program in c. almost because c isnt a "modern age" language. you cant make 3d graphic games with c, with surround sound and etc... u get what i mean?

    but it's a very good "academic" language, as my professor puts it.
    It is not who I am inside but what I do that defines me.

  8. #8
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    > What type of programs can you make in C? Is it mainly mathmatical programs?

    Actually, the opposite seems to be true: making mathematical programs in C can be quite difficult, such as the one members are working on in the current contest. One reason is because the standard math library provides some neat calculations and some constants, but that's it. To me, this means that math isn't a huge part of C's job. As your course progresses, you'll write stuff that has nothing to do with math at all.

  9. #9
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    alpha im not being rude but do one yourself! start with the basics, post back progress when you get stuck with something and someone will help.

    - read in one number (float)
    - read in one char (for operator / * + or -)
    - read in one number (float)

    display the result of the two numbers after the appropriate operation is applied

  10. #10
    The C eater *munch*
    Join Date
    Oct 2006
    Posts
    101
    play around with code, in ur example, scanf will be your best friend

  11. #11
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Quote Originally Posted by yxunomei
    scanf will be your best friend
    Or your worst enemy.
    http://www.daniweb.com/tutorials/tutorial45806.html
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  12. #12
    The C eater *munch*
    Join Date
    Oct 2006
    Posts
    101
    lol... ok, assuming ur not a novice, u can use fgets and sscanf

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. creating very simple text editor using c
    By if13121 in forum C Programming
    Replies: 9
    Last Post: 10-19-2010, 05:26 PM
  2. Simple message encryption
    By Vicious in forum C++ Programming
    Replies: 10
    Last Post: 11-07-2004, 11:48 PM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. Simple simple program
    By Ryback in forum C++ Programming
    Replies: 10
    Last Post: 09-09-2004, 05:48 AM
  5. Need help with simple DAQ program
    By canada-paul in forum C++ Programming
    Replies: 12
    Last Post: 03-15-2002, 08:52 AM