![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Mar 2009
Posts: 10
Rep Power: 0
![]() |
Calculate using '-' HELP!
Hi, this is neary working how i want it exept i cant calculate negative numbers
example- (-56 67 +). at one stage it was but i messed the code up abit and now cant seem to fix it. C Syntax (Toggle Plain Text)
|
|
|
|
|
|
#2 |
|
Programming Guru
![]() Join Date: Jun 2005
Posts: 1,170
Rep Power: 6
![]() |
Re: Calculate using '-' HELP!
I think your problem is with this test:
if ((!isdigit(Str1[x])) & (Str1[0] != '-')) Something like: if (! (isdigit(Str1[x]) || (x == 0 && (Str1[0] == '-'))) k = 1; Note that you should use && for boolean 'and', a single & is bitwise 'and'. Also note, if you are checking the string content, you should also be checking the return value from scanf. |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Mar 2009
Posts: 10
Rep Power: 0
![]() |
Re: Calculate using '-' HELP!
above Solution didn't work at all.. Plz help anyone..
|
|
|
|
|
|
#4 |
|
Programming Guru
![]() Join Date: Jun 2005
Posts: 1,170
Rep Power: 6
![]() |
Re: Calculate using '-' HELP!
above solution works fine. It was missing a bracket at the end of the if test which would have been pointed out by your compiler.
You also have the isdigit redeclared locally which stopped your code working on my computer. You also have switch(Operator) where Operator is a char array - this isn't allowed (at least on my compiler) and would certainly not work as you are expecting even if the compiler allowed it. You need switch(Operator[0]). Also, this line: scanf(" %s", &Operator);PS. "didn't work at all" is not a useful message. You would do much better by saying what didn't work. |
|
|
|
|
|
#5 |
|
Newbie
Join Date: Mar 2009
Posts: 10
Rep Power: 0
![]() |
Re: Calculate using '-' HELP!
Yes u are right.. Thanks a great deal
|
|
|
|
|
|
#6 |
|
Healthy Programmer
Join Date: Jun 2009
Posts: 27
Rep Power: 0
![]() |
Re: Calculate using '-' HELP!
Yeah i agree with u
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| calculate distance using values in an array | annie_singh | Perl | 3 | Oct 4th, 2008 11:33 PM |
| VB.NET: Loops - calculate selected items | jaybird01 | Visual Basic .NET | 7 | Aug 14th, 2006 5:35 AM |
| need help on how to calculate between 2 input times. | oslan | C | 18 | Feb 14th, 2006 9:15 PM |
| Problem with calculate difference between two dates!!! | Esroh | Java | 3 | May 26th, 2005 9:39 AM |