![]() |
|
#1
|
|||
|
|||
Simple Calculator in CHey all im new as a member but have browsing for a little bit of time since ive had my basic c programming class this semester. im working on this simple calculator and the problem reads:
Write a program to model a simple calculator. Each data line should consist of the next operation to be performed from the list below and the right operand. Assume the left operand is the accumulator value (initial value of 0). You need a function scan_data with two output parameters that returns the operator and right operand scanned from a data line. You need a function do_next_op that performs the required operation. do_next_op has two input parameters (the operator and operand) and one input/output parameter (theaccumulator). The valid operators are: + add - subtract * multiply / divide ^ power (raise left operand to power of right operand)q quit Your calculator should display the accumulator value after each operation. A sample run follows. + 5.0 result so far is 5.0 ^ 2 result so far is 25.0 / 2.0 result so far is 12.5 q 0 final result is 12.5 Ive got part of the program writen and i was wondering how you guys think it looks and if i just finish it up if it will work. thanks for any help. heres what i have written: CPP / C++ / C Code:
Last edited by LuciWiz : 24-Oct-2006 at 14:01.
Reason: Please insert your C/C++ code between [cpp] & [/cpp] tags
|
|||
|
#2
|
|||
|
|||
Re: Simple Calculator in Coh ya and we are supposed to use pointers, and functions.
|
|
#3
|
|||
|
|||
Re: Simple Calculator in Cso after you scan the stuff, do you wait for the next integer input, then
calculate and output? or do you keep accumulating until they answer a negative number... so far it looks good... |
|
#4
|
|||
|
|||
Re: Simple Calculator in Cwe are just supposed to keep accumulating until they press q
|
|
#5
|
|||
|
|||
Re: Simple Calculator in Cwell ive revised my program quite a bit and it seems much simpler. i would have edited the post but i wasnt able to.
im still having some trouble on the accumulator. im getting errors there. so any help would be appriciated. heres the code: CPP / C++ / C Code:
here are the errors when i try to compile the program hw4.c:55: warning: conflicting types for 'do_next_op' hw4.c:14: warning: previous declaration of 'do_next_op' was here hw4.c: In function `do_next_op': hw4.c:58: error: 'accum' redeclared as different kind of symbol hw4.c:54: error: previous definition of 'accum' was here Last edited by admin : 07-Apr-2007 at 11:36.
Reason: Please insert your C code between [cpp] & [/cpp] tags
|
|
#6
|
|||
|
|||
Re: Simple Calculator in CYou didn't put a return type for do_next_op where you defined the function, whereas at the prototype it says void. The compiler assumes int if you put nothing there, so those are different and the compiler complains. It looks like you want it to be void, so make it void.
Now, in the do_next_op function there is a parameter accum, which is a pointer to a double, and then you try to declare a double variable accum. This won't work. To assign a value to the variable which the parameter accum points to, you just do this: *accum = *accum + num_2; Review pointers if this doesn't make sense. |
|
#7
|
|||
|
|||
Re: Simple Calculator in Cthanks i made that change and everything compiles alright but the program isnt returning the values that i would like. i also cant get it to quit.
heres what i have: CPP / C++ / C Code:
Last edited by admin : 07-Apr-2007 at 11:37.
Reason: Please insert your C code between [cpp] & [/cpp] tags
|
|
#8
|
|||
|
|||
Re: Simple Calculator in CYour scan_data function does nothing. It reads in some values to local variables, and then deletes those variables. You forgot
CPP / C++ / C Code:
|
|
#9
|
|||
|
|||
Re: Simple Calculator in CsTill it is not working ... can u write the code properly
??? |
Recent GIDBlog
Problems with the Navy (Enlisted) by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| how to write a simple calculator code? Help! | JavaLost | Java Forum | 2 | 24-Oct-2006 02:41 |
| a simple question | sharwar | .NET Forum | 3 | 28-Sep-2006 06:18 |
| UpdateData - simple MFC project | kobycool | MS Visual C++ / MFC Forum | 3 | 23-Oct-2005 03:45 |
| Simple Calculator Application | MOHAMMEDALI1989 | Java Forum | 1 | 06-Oct-2005 18:00 |
| Just need one simple example or link to such example | Doggonit | MySQL / PHP Forum | 2 | 31-Jul-2005 19:39 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The