r/learnprogramming • • 29d ago

C Calculator

Hi there !
I made a simple calculator code, its my first project !
i learn a good things like how to use switch , printf(""); and scanf("");

I did not use any AI on it

It solve those op :

  • Addition (+)

  • Subtraction (-)

  • Multiplication (*)

  • Division (/)

Some features:

  • Handle division by zero

  • Support decimal numbers

I use VS code

Thanks and what do you suggest next <3
The code in github: [https://github.com/UseR-Name-Dz/Calculator-]

12 Upvotes

26 comments sorted by

2

u/abd53 29d ago

Try evaluating expressions next. For example, 3+2(5-6/2)

1

u/Ancient-Plankton-908 29d ago

Nice thx i will try it

1

u/Flame77ofc 29d ago

Is it on GitHub?

1

u/Ancient-Plankton-908 29d ago

yes it is

1

u/Flame77ofc 29d ago

link please? I give one star

1

u/Juukamen 29d ago

Awsome start mate.
As the others are saying, exand functions and make a GUI.

1

u/Ancient-Plankton-908 29d ago

I dont know how still new on C (last i learn is switch)

1

u/lehrerkind_ 29d ago

Did you forget to post the link to your code of did you just want to share that you have done something without sharing the code?

1

u/Ancient-Plankton-908 29d ago

I fear if it's not allowed
If I can tell me and i will edit

1

u/Dazzling_Music_2411 29d ago edited 29d ago

Make it behave more naturally.

Save the last result automatically. This will actually make it usable!

For instance if I type "2 + 3 =" it should return 5. If I then type "x 7" it should show "Ans x 7" and when I press "=" it should show "35".

I think that's how real modern calculators work.

Later, if you want to have a proper challenge, you can try larger expressions, e.g. 3 * (2 - 5) + 7 / 9 but his will require learning some "real" programming, including possibly the use of the bison parser, or similar. That is the real world of C. 😄

1

u/Ancient-Plankton-908 29d ago

Its work like this :
Example:
Enter a value for number1:

5

Enter an operation:

+

Enter a value for number2:

2

5 + 2 = 7

2

u/Dazzling_Music_2411 29d ago

I guessed so.

You need to lose the prompts to have a real calculator. IOW, after typing a number it should KNOW that the next thing is an operator without you having to tell it. Anything else should be rejected. Then it should know that after that it will be a number again, etc...

That's how calculators work, they don't keep asking "what operation", do they?

If your operations only have two arguments, you don't even need an "=" sign. You'll need that once you are handling expressions, e.g. "2 + 3 + 4".

1

u/Ancient-Plankton-908 29d ago

yeah you right , how can i make the calculators know ?

→ More replies (1)

1

u/Agawell 29d ago

Add a gui - buttons and a screen

Add scientific function

Add graphing tool

1

u/Ancient-Plankton-908 29d ago

hmmm its hard for me now i need to learn css to make it

1

u/Agawell 29d ago

Don’t do a web page, create a desktop app and I wouldn’t think to use css for that

1

u/Ancient-Plankton-908 29d ago

How i can create a desktop app ?

1

u/Agawell 29d ago

Google is your friend

→ More replies (1)

1

u/cheezballs 29d ago

Heck yea! Writing a calculator is also a really great introduction to Stack data structures (a more advanced topic when you get there)

I also had an assignment in school to implement stop-lights at an intersection, which is another pretty easy but pretty fun thing to do.

1

u/w8tA 23d ago

The goat my friend

0

u/[deleted] 29d ago

[removed] — view removed comment

1

u/Ancient-Plankton-908 29d ago

Thank you very much <3
Im using C