![]() |
|
|||||||
|
|
Thread Tools | Search this Thread | Rate Thread |
|
#1
|
|||
|
|||
Write a calculator program that lets users enter a simple mathematic operationFor your all informations ..... I'm a newbie in C programming ....
Can somebody help me to solve this problem ?? Write a calculator program that lets users enter a simple mathematic operation and display the results as in the sample output shown below (bold text indicates user input). Calculate: 92 + 1 Result = Ninety Three Calculate: 92, 000 + 1 Result = Ninety Two Thousand Calculate: 92, 000.01 + 1 Result = Ninety Two Thousand and One Point Zero One Calculate: 92, 000.01 * 1 + 1 / 1 Result = Ninety Two Thousand and One Point Zero One our program MUST at least be able to interpret the following operators: • + • - • / • * • % • > • < • >= • <= The results should be in string and the 92,000 got comma one , a bit hard for me to solve it ..... Can solve it and discuss it here ? |
|||
|
#2
|
|||
|
|||
Re: Can help me to solve this problem ??the calculator part is quite easy, but you may have to input data on separate lines like:
92 + 1 you would have to use scanf() to recognise the numbers and use a switch function for the sum like: CPP / C++ / C Code:
you could use a switch statement with the numbers 0-9 and their names to be used for each digit, but the output would be more like Zero Nine Three Point Zero Zero To get a better out put you would have to make several switch statments, one for each digit. Last edited by admin : 21-Aug-2008 at 15:27.
Reason: Please insert your example C/C++ codes between [CPP] and [/CPP] tags
|
|
#3
|
|||
|
|||
Re: Can help me to solve this problem ??So anybody can help me ???
|
|
#4
|
|||
|
|||
Re: Can help me to solve this problem ??Quote:
no you will need to do it like this: CPP / C++ / C Code:
If you did it the hard way you would have to make 7 swich statements, one for each digit, plus a system for sorting out teens Last edited by admin : 21-Aug-2008 at 15:27.
Reason: Please insert your example C/C++ codes between [CPP] and [/CPP] tags
|
|
#5
|
|||
|
|||
Re: Can help me to solve this problem ??Quote:
Now to answer your question, try to establish patterns. ie.
|
|
#6
|
|||
|
|||
Re: Can help me to solve this problem ??You do not need 1000 cases. You should probably be able to convert it to a string first, then analyze each character. You will have to calculate the offset from the decimal character and decide whether it represents hundreds, tens, or ones. If the number is a 3 and it's in the tens spot then you know it is "thirty". After each 3 numbers, you'll need to decide whether the offset represents thousands, millions, billions, trillions, etc. (Can we assume a limit of 999.999999999999 trillion?) then append the proper word. So, for example, lets say the number is 1234567.89.
Code:
|
|
#7
|
|||
|
|||
Re: Can help me to solve this problem ??Calculate: 92, 000.01 * 1 + 1 / 1
If i do exactly what bobsam wrote , i cant have 3 variables for the calculation part ..... Is it cannot use switch ? or ? And , thanks for your all ......You all are really nice ..... Really , thanks a lots ! |
|
#8
|
||||
|
||||
Re: Can help me to solve this problem ??Quote:
Quote:
For example, given the expression 2 + 3 * 4, the proper answer is 14. If operator precedence is relaxed, the answer may be 20. You should also clarify whether parentheses are potential characters seen in the input stream. Quote:
Quote:
|
|
#9
|
|||
|
|||
Re: Can help me to solve this problem ??Oh ... then the correct way is still usong switch to do it ? Thanks for teaching me . And also thanks to Bobsam
|
|
#10
|
|||
|
|||
Re: Can help me to solve this problem ??Quote:
|
Recent GIDBlog
Review: Gel laptop cooling pad by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| An easy problem solve for most of you | slapshot6819 | C++ Forum | 2 | 20-Nov-2007 03:14 |
| Please help me to solve C++ problem | fahad | C++ Forum | 1 | 01-Nov-2007 05:43 |
| Problem Description: Graph’s Degree.....can help me to solve this out? | thefinalyy | C++ Forum | 0 | 24-Aug-2007 06:42 |
| I have a problem to solve summation in c++ | logieen | C++ Forum | 4 | 22-May-2007 08:25 |
| A problem using streams. (I've spent a month trying to solve it) | Mararia | C++ Forum | 8 | 14-Dec-2006 17:52 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The