Click here to Skip to main content
15,884,629 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
This is Roger.I dont have pretty good idea on .NET.Could any one please help me in coding a simple calculator program in VC# 2008(Console application).This is very much urgent.I am reading the stuff related to .Net but I am not able to implement that in the programming.

Specification

Requirement
In this you are to prepare a C# program that will act as a simple calculator. The
calculator will be run from the command line and will only work with integer numbers and
the following arithmetic operators + - * / %. The % operator is the modulus operator, not
the percentage.
For example, if the C# program is compiled to calc.exe, the following demonstrates how it
will work
calc 3 + 5 - 7
1
In the command line, the arguments are a repeated sequence in the form
number operator
and ending in a
number
Hitting the enter key will cause the program to evaluate the arguments and print the result. In
this case 1.
The program must follow the usual laws of arithmetic which says
1. The * / and % operators must all be evaluated before the + and – operators.
2. Operators must be evaluated from left to right.
For example, using Rule 1
2 + 4 * 3 – 6
becomes
2 + 12 – 6
which results in
8
If we did not use Rule 1 then 2 + 4 * 3 – 6 would become 6 * 3 – 6 and then
18 – 6 and finally 12. This is an incorrect result.

If we do not use Rule 2 then the following illustrates how it can go wrong
4 *<b></b> 5 % 2
Going from left to right we evaluate the * first, which reduces the expression to 20 % 2
which becomes 0. If we evaluated the % first then the expression would reduce to 4 * 1
which becomes 1. This is an incorrect result. Remember, we are using integer mathematics
when doing our calculations, so we get integer results when doing division. For example
calc 20 / 3
6
Also note that we can use the unary + and – operators. For example
calc -5 / +2
-2
Your program must also check to make sure the command line arguments are correct. If not
your program must generate an appropriate error message and then terminate.


This is the specification of my requirement.Could any one please help me out in giving out a correct coding for this.



Thanking you

Roger.
Posted
Comments
Richard MacCutchan 27-Sep-10 12:04pm    
It's pretty clear from the above that this is a homework or college assignment, so if you really do not know what to do you should reread some of your study guides and/or talk to your tutor.

1 solution

Well see here or maybe here.

Noone is going to give you the entire code for the problem.
 
Share this answer
 
v2
Comments
Sandeep Mewara 28-Sep-10 15:01pm    
Comment from OP:

Hey Abhinav
Thank you very much for the code that has been given to me by you.One of the program is a worth of going with.One thing I dont understand here is that I am not able to execute them is there any problem in the code or is there.The second link is the correct code that works with e.So If you can pls help me in executing as well.As I am a management(MBA) guy and this .net was a compulsory subject for me here in my clg and I dont have any good idea on this programming.I am not at all related to this programming field.I told the same to my lecturer but he tells me to have a thorough reading from online .After using so many sources then I found only this would help me out in helping me.Pls help me abhinav how to excute the file which was a second link given to me by you.Or else i may fail in my subject.

thanking you
Roger
Abhinav S 29-Sep-10 1:54am    
Thanks Sandeep.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900